Site dont connect database.

zoumhs

Выдающийся
Участник
Сообщения
152
Розыгрыши
0
Репутация
0
Реакции
34
Баллы
1 345
hello guys good evening, im trying to configure my site to connect to dedicate machine, already i have opened 1433 port and in port checker looks open every time o check it with ip. but when i put to the site config ip and database password etc. my site get http error 500 for no reason. i have try already 3 site accounts panels and sites again the same issue. my question now is maybe i need open and something else or?
 

zoumhs, run command line on your home pc and enter (telnet <IP address of your dedicated server> <port SQL Server>)
Bash:
telnet 8.8.8.8 1433
if after entering the telnet command a blank black screen appears, then the port was opened correctly
1630743114248.png
otherwise check your firewall settings / settings SQL Server Configuration manager

to check the connection to the remote database from the site.
create file dbtest.php at site root and execute it (enter in browser domain.com/dbtest.php)
PHP:
<?php

$availableDrivers = PDO::getAvailableDrivers();

$driver = 'sqlsrv';

if ( !in_array( $driver, $availableDrivers ) )
{
    echo '<pre>Available drivers:<br>';
    print_r( $availableDrivers );
    echo '</pre>';
    die( "Driver <b>$driver</b> not supported" );
}

$dbhost = '8.8.8.8';
$dbport = 1433;
$dbuser = 'sa';
$dbpass = '12345';
$dbname = 'lin2db';

try
{
    $dbh = new \PDO( "$driver:Server=$dbhost,$dbport;Database=$dbname", $dbuser, $dbpass );
}
catch ( \PDOException $e )
{
    die( $e->getMessage() );
}

echo 'Connected!';

?>

status code 500 - reason syntax error in php code and/or many other reasons
 
zoumhs, run command line on your home pc and enter (telnet <IP address of your dedicated server> <port SQL Server>)
Bash:
telnet 8.8.8.8 1433
if after entering the telnet command a blank black screen appears, then the port was opened correctly
Посмотреть вложение 38725
otherwise check your firewall settings / settings SQL Server Configuration manager

to check the connection to the remote database from the site.
create file dbtest.php at site root and execute it (enter in browser domain.com/dbtest.php)
PHP:
<?php

$availableDrivers = PDO::getAvailableDrivers();

$driver = 'sqlsrv';

if ( !in_array( $driver, $availableDrivers ) )
{
    echo '<pre>Available drivers:<br>';
    print_r( $availableDrivers );
    echo '</pre>';
    die( "Driver <b>$driver</b> not supported" );
}

$dbhost = '8.8.8.8';
$dbport = 1433;
$dbuser = 'sa';
$dbpass = '12345';
$dbname = 'lin2db';

try
{
    $dbh = new \PDO( "$driver:Server=$dbhost,$dbport;Database=$dbname", $dbuser, $dbpass );
}
catch ( \PDOException $e )
{
    die( $e->getMessage() );
}

echo 'Connected!';

?>

status code 500 - reason syntax error in php code and/or many other reasons
I get this.

if i write sqlite its saying connected.
 

Вложения

  • Screenshot (158).png
    Screenshot (158).png
    20 КБ · Просмотры: 43
sqlite not to connect to SQL Server. Check with technical support hosting the possibility of connecting to a remote database Microsoft SQL Server

zoumhs, alternative connection methods test
PHP:
<?php

ini_set( 'display_errors', '1' );
error_reporting( E_ALL );

$dbhost = '8.8.8.8';
$dbport = 1433;
$dbuser = 'sa';
$dbpass = '12345';
$dbname = 'lin2db';

if ( function_exists( 'mssql_connect' ) )
{
    $dblink = mssql_connect( "$dbhost,$dbport", $dbuser, $dbpass );
    
    if ( $dblink )
    {
        echo 'mssql_ Connected!';
        mssql_close( $dblink );
    }
    else
        echo mssql_get_last_message() . '<br>';
}
else
    echo 'Function mssql_* not supported<br>';

if ( function_exists( 'sqlsrv_connect' ) )
{
    $dblink = sqlsrv_connect( "$dbhost,$dbport", [ "Database" => $dbname, "UID" => $dbuser, "PWD" => $dbpass ] );
    
    if ( $dblink )
    {
        echo 'sqlsrv_ Connected!';
        sqlsrv_close( $dblink );
    }
    else
    {
        echo '<pre>sqlsrv errors:<br>';
        print_r( sqlsrv_errors() );
        echo '</pre>';
    }
}
else
    echo 'Function sqlsrv_* not supported<br>';

?>
 
sqlite not to connect to SQL Server. Check with technical support hosting the possibility of connecting to a remote database Microsoft SQL Server

zoumhs, alternative connection methods test
PHP:
<?php

ini_set( 'display_errors', '1' );
error_reporting( E_ALL );

$dbhost = '8.8.8.8';
$dbport = 1433;
$dbuser = 'sa';
$dbpass = '12345';
$dbname = 'lin2db';

if ( function_exists( 'mssql_connect' ) )
{
    $dblink = mssql_connect( "$dbhost,$dbport", $dbuser, $dbpass );
   
    if ( $dblink )
    {
        echo 'mssql_ Connected!';
        mssql_close( $dblink );
    }
    else
        echo mssql_get_last_message() . '<br>';
}
else
    echo 'Function mssql_* not supported<br>';

if ( function_exists( 'sqlsrv_connect' ) )
{
    $dblink = sqlsrv_connect( "$dbhost,$dbport", [ "Database" => $dbname, "UID" => $dbuser, "PWD" => $dbpass ] );
   
    if ( $dblink )
    {
        echo 'sqlsrv_ Connected!';
        sqlsrv_close( $dblink );
    }
    else
    {
        echo '<pre>sqlsrv errors:<br>';
        print_r( sqlsrv_errors() );
        echo '</pre>';
    }
}
else
    echo 'Function sqlsrv_* not supported<br>';

?>
 

Вложения

  • Screenshot_20210904-190930.jpg
    Screenshot_20210904-190930.jpg
    54 КБ · Просмотры: 38
ask a question to the hosting technical support about support for remote connection to Microsoft SQL Server database
I have changed the host to hostchefs.eu i hope will work

Today from new hosting i get this error with testdb.php

SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64:

I have changed the host to hostchefs.eu i hope will work

Today from new hosting i get this error with testdb.php

SQLSTATE [IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64:
 

Вложения

  • Screenshot (159).png
    Screenshot (159).png
    26,5 КБ · Просмотры: 18
$conMethod = 2;
// 1 = MsSQL,
2 = SQLSR,
3= ODBC,
4 = PDO-ODBC
 
zoumhs, if // 1 = MsSQL this function mssql_* (mssql_connect end etc) then these methods in php 5.3 are marked as deprecated and removed in version 7.0

Other connection methods are available after installing additional software, which is rarely seen on hosting.

options
  • on hosting downgrade php version (< 7.0) and try $conMethod = 1 (MsSQL)
  • use VPS/VDS (install manual software webserver) + install additional software support connection SQL Server (ODBC, sqlsrv, Sybase
    and etc)
 
zoumhs, if // 1 = MsSQL this function mssql_* (mssql_connect end etc) then these methods in php 5.3 are marked as deprecated and removed in version 7.0

Other connection methods are available after installing additional software, which is rarely seen on hosting.

options
  • on hosting downgrade php version (< 7.0) and try $conMethod = 1 (MsSQL)
  • use VPS/VDS (install manual software webserver) + install additional software support connection SQL Server (ODBC, sqlsrv, Sybase
    and etc)
excellent job my friends, downgrade to 5. 4 php and change to 1 and fixed
 
Назад
Сверху Снизу