Unable to connect to SQL Server with PHP

前端 未结 3 1854
粉色の甜心
粉色の甜心 2020-12-17 22:06

Connection to sqlsrv string not working.

$login = new PDO(\"sqlsrv:server=MYSQLSERVER\\SQLEXPRESS;Database=db_name\", \"user\", \"passw\");


        
相关标签:
3条回答
  • 2020-12-17 22:30

    Looks like to connect to MS-SQL, you will need to utilize ODBC.

    Reference:http://php.net/manual/en/pdo.construct.php#120705

    $odbc="odbc:Driver={SQL Server};Server=$server;Database=$database;";
    
    $cnx = new PDO( $odbc , $user, $password);
    
    0 讨论(0)
  • There's a problem with PHP Sql Server driver
    You should update it to new version

    As you mentioned you are using windows, this version is fully working on windows

    https://github.com/Microsoft/msphpsql/releases/tag/v4.1.1-Windows

    0 讨论(0)
  • 2020-12-17 22:55

    Try "ConnectionPooling=0" in DSN.

    sometimes working and sometimes return error

    It might be a problem on re-using connection.

    DSN Reference: https://msdn.microsoft.com/en-us/library/ff628167(v=sql.105).aspx

    0 讨论(0)
提交回复
热议问题