Unable to connect to msSQL database via PHP

前端 未结 9 536
余生分开走
余生分开走 2021-01-13 07:30

I am using the current code in attempt to access a msSQL 2005 db:



        
9条回答
  •  梦谈多话
    2021-01-13 08:35

    stop using

    mssql_connect

    and start using

    sqlsrv_connect

    That will save you a lot of headaches. Plus, the function *mssql_connect* has been deprecated.

    For using sqlsrv_connect, you must download the driver and install it as an extension for PHP to recognize the sqlsrv functions. Download the driver from Microsoft Download Center (search for "sql server php driver"), at the time of this post the download url was: http://www.microsoft.com/en-us/download/details.aspx?id=20098

    The right steps for installation are clearly explained by Microsoft itself at http://www.microsoft.com/en-us/download/details.aspx?id=20098

    1. download the driver. 2. put it in the PHP ext folder. 3. update the php.ini 4. restart the server.

    After installing the sql server driver, then simply follow the instructions from http://www.php.net/manual/en/function.sqlsrv-connect.php. Below a quick snippet:

    "dbName");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
    if( $conn ) {
         echo "Connection established.
    "; }else{ echo "Connection could not be established.
    "; die( print_r( sqlsrv_errors(), true)); } ?>

    Vote up!

提交回复
热议问题