locked
PHP cannot connect to SQL SERVER 2005...I've triple checked everything RRS feed

  • Question

  •  

    sorry! repost! I should have filed this as a new thread instead of commenting on an existing thread with the SAME problem!

     

    Yes I've triple checked my new install of PHP for SQL Server 2005

     

    I've tried all the following and got error messages

     

    My IIS works for other non MS SQL Server operations!

     

    The code below comes from MS sites!

     

    (1)

    <?php
    // Server in the this format: <computer>\<instance name> or
    // <server>,<port> when using a non default port number
    // $server = 'LANDON\SQLEXPRESS';                                    didn't work either

    $server = '(local)\sqlexpress';
    $link = mssql_connect($server, 'sa', 'PW');

    if(!$link)
    {
        die('Something went wrong while connecting to MSSQL');
    }
    ?>

     

    error:

     

    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: (local)\sqlexpress in C:\Inetpub\wwwroot\trymssql.php on line 7
    Something went wrong while connecting to MSSQL

     

    (2)  code from MS site!

     

    <?php
    /* Specify the server and connection string attributes. */
    $serverName = "(local)";
    $connectionInfo = array( "Database"=>"AdventureWorks");

    /* Connect using Windows Authentication. */
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn === false )
    {
         echo "Unable to connect.</br>";
         die( print_r( sqlsrv_errors(), true));
    }

    /* Query SQL Server for the login of the user accessing the
    database. */
    $tsql = "SELECT CONVERT(varchar(32), SUSER_SNAME())";
    $stmt = sqlsrv_query( $conn, $tsql);
    if( $stmt === false )
    {
         echo "Error in executing query.</br>";
         die( print_r( sqlsrv_errors(), true));
    }

    /* Retrieve and display the results of the query. */
    $row = sqlsrv_fetch_array($stmt);
    echo "User login: ".$row[0]."</br>";

    /* Free statement and connection resources. */
    sqlsrv_free_stmt( $stmt);
    sqlsrv_close( $conn);
    ?>

     

    ERROR:

     

    Unable to connect.
    Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [2]. [message] => [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [2]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Native Client]Login timeout expired [message] => [Microsoft][SQL Native Client]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. [message] => [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. ) )

     

    (3) downloaded adventure works .msi and successfully installed,,,no tables found in SQL server 2005 database


     

     

    Tuesday, December 9, 2008 6:17 PM

Answers

  • The new driver that a-joelpe_MSFT is referring to is the SQL Server Driver for PHP 1.0 CU1 Release Announcement.  The API prefix for all its functions are sqlsrv_ rather than mssql_.

    This forum is dedicated to that driver.  The mssql driver is not supported by Microsoft.  The php.ini entry to load our driver is "extension=php_sqlsrv.dll" if you're using a non-threaded build of PHP, or "extension=php_sqlsrv_ts.dll" if you're using a threaded build of PHP.

    Hope this helps.  If you convert your application to our driver and continue to experience difficulties, please reply to this thread or start a new one and we will be happy to help you.

     


    Jay Kint MSFT
    • Proposed as answer by David Sceppa Monday, March 9, 2009 5:39 PM
    • Marked as answer by David Sceppa Monday, March 9, 2009 7:43 PM
    Tuesday, March 3, 2009 8:02 PM

All replies

  • I think you need to attach the AdventureWorks database after running the .msi. This article should help: How to: Attach a Database. And, as the error message indicates, your server needs to be configured for remote connections. This article should help with that: How to Configure SQL Server to Allow Remote Connections.

     

    Let us know if those articles don't help.

     

    -Brian

    Tuesday, December 9, 2008 7:29 PM
  • you can also try .\SQLEXPRESS as the host, but either way you should be using the new sqlsrv driver anyway
    Tuesday, December 9, 2008 10:05 PM
  •  

    I am using the new driver and php.ini has:

     

    ;;;;;;;;;;;;;;;;;;;;;;
    ; Dynamic Extensions ;
    ;;;;;;;;;;;;;;;;;;;;;;
    ;
    ; If you wish to have an extension loaded automatically, use the following
    ; syntax:
    ;
    ;   extension=modulename.extension
    ;
    ; For example, on Windows:
    ;
    ;   extension=msql.dll
    [SQL_Server_2005]
    extension=php_sqlsrv_ts.dll
    ;
    ; ... or under UNIX:
    ;
    ;   extension=msql.so
    ;
    ; Note that it should be the name of the module only; no directory information
    ; needs to go here.  Specify the location of the extension with the
    ; extension_dir directive above.


    ; Windows Extensions
    ; Note that ODBC support is built in, so no dll is needed for it.
    ; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
    ; extension folders as well as the separate PECL DLL download (PHP 5).
    ; Be sure to appropriately set the extension_dir directive.

    ;extension=php_bz2.dll
    ;extension=php_curl.dll
    ;extension=php_dba.dll
    ;extension=php_dbase.dll
    ;extension=php_exif.dll
    ;extension=php_fdf.dll
    ;extension=php_gd2.dll
    ;extension=php_gettext.dll
    ;extension=php_gmp.dll
    ;extension=php_ifx.dll
    ;extension=php_imap.dll
    ;extension=php_interbase.dll
    ;extension=php_ldap.dll
    ;extension=php_mbstring.dll
    ;extension=php_mcrypt.dll
    ;extension=php_mhash.dll
    ;extension=php_mime_magic.dll
    ;extension=php_ming.dll
    ;extension=php_msql.dll
    extension=php_mssql.dll
    ;extension=php_mysql.dll
    ;extension=php_mysqli.dll
    ;extension=php_oci8.dll
    ;extension=php_openssl.dll
    ;extension=php_pdo.dll
    ;extension=php_pdo_firebird.dll
    ;extension=php_pdo_mssql.dll
    ;extension=php_pdo_mysql.dll
    ;extension=php_pdo_oci.dll
    ;extension=php_pdo_oci8.dll
    ;extension=php_pdo_odbc.dll
    ;extension=php_pdo_pgsql.dll
    ;extension=php_pdo_sqlite.dll
    ;extension=php_pgsql.dll
    ;extension=php_pspell.dll
    ;extension=php_shmop.dll
    ;extension=php_snmp.dll
    ;extension=php_soap.dll
    ;extension=php_sockets.dll
    ;extension=php_sqlite.dll
    ;extension=php_sybase_ct.dll
    ;extension=php_tidy.dll
    ;extension=php_xmlrpc.dll
    ;extension=php_xsl.dll
    ;extension=php_zip.dll

     

     

    Wednesday, December 10, 2008 1:36 AM
  • attachment worked...I learned something!

     

    I do remember the northwind data base attaching itself!

     

    I've run out of ideas except for the general area of permissions.

     

    What permissions does the web server php have?

    Wednesday, December 10, 2008 1:47 AM
  •  

    In the area of permissions, I've checked administrative tools...local security policy

     

    SQL SERVER management studio express I've given myself every privilege (connect was already set)

     

    the IIS 5.1 server must have permission to log into the sql server 2005 given the windows authentication

     

    sa

    password for XP prof administrator login

     

     

    <?php
    $myServer = "LANDON\SQLEXPRESS";

    $myUser = "sa";
    $myPass = "xoxoxo";
    //connection to the database
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
      or die("Couldn't connect to SQL Server on $myServer");

    mssql_close($dbhandle);
    ?>

     

    I am missing something simple SQL SERVER people know implicitly

    Wednesday, December 10, 2008 4:09 AM
  • obviously NOT answered yet.

    I got an email to return to thread and report status.
    Friday, December 12, 2008 7:15 PM
  •  You should be able to login using SQL Server Authentication, but the sa password isn't necessarily the same as the Administrator password for your computer. What password are you using when you connect with SQL Server Management Studio (SSMS)?

    If you can connect to the server using SSMS, you could create a new login (with whatever permissions you would like) and password, then use those credentials to login.

    -Brian
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Saturday, December 13, 2008 1:18 AM
  • The new driver that a-joelpe_MSFT is referring to is the SQL Server Driver for PHP 1.0 CU1 Release Announcement.  The API prefix for all its functions are sqlsrv_ rather than mssql_.

    This forum is dedicated to that driver.  The mssql driver is not supported by Microsoft.  The php.ini entry to load our driver is "extension=php_sqlsrv.dll" if you're using a non-threaded build of PHP, or "extension=php_sqlsrv_ts.dll" if you're using a threaded build of PHP.

    Hope this helps.  If you convert your application to our driver and continue to experience difficulties, please reply to this thread or start a new one and we will be happy to help you.

     


    Jay Kint MSFT
    • Proposed as answer by David Sceppa Monday, March 9, 2009 5:39 PM
    • Marked as answer by David Sceppa Monday, March 9, 2009 7:43 PM
    Tuesday, March 3, 2009 8:02 PM
  • As Jay points out, this is forum is specifically to help PHP developers working with the Microsoft SQL Server Driver for PHP, which uses the function prefix sqlsrv_.

    We invite you to go to the announcement that Jay referenced above to download the extension and try using it to talk to your SQL Server database from your PHP code.

    David Sceppa
    Program Manager - SQL Server Driver for PHP
    Monday, March 9, 2009 5:42 PM
  • I fixed this problem withing days of posting the original.

    The directions for installing PHP are not accurate.

    My working PHP mssql_connect code is elsewhere on this forum.
    Monday, March 9, 2009 7:38 PM
  • Glad to hear you have your code working properly.

    David Sceppa

    Program Manager - SQL Server Driver for PHP

    Monday, March 9, 2009 7:42 PM