none
Fatal error: Call to undefined function sqlsrv_connect()

    Question

  • Hi ,

    This is Tamilmani Mohan . I am new entry for this forum . I have an question PHP SQLAzure Connection .

    1. I want to connect my db by using SqlAzure .

    I followed below steps

    1. I have downloaded SQLServerDriverForPHP

    2. Extract the folder , all the dll files put into my php extension directory .

    3. I added the new line in php.ini file
    extension=php_sqlsrv_ts.dll

    4. I created the sample php page in local directory

    following codes are i typed .

    $serverName = "(local)";
    $connectionInfo = array( "Database"=>"CRLOCAL");

    /* Connect using Windows Authentication. */
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn === false )
    {
         echo "Could not connect.\n";
         die( print_r( sqlsrv_errors(), true));
    }
    /* Free the statement and connectin resources. */
    sqlsrv_free_stmt( $stmt );
    sqlsrv_close( $conn );


    But I am getting Fatal error: Call to undefined function sqlsrv_connect()

    Please one tell me how to resolve this

    Thanks

    Tamilmani Mohan
    Thursday, February 25, 2010 7:12 PM

Answers

  • Hi ,

    I configured everything in properly . I don't get anything in my php info .So tell me the steps .


    Thanks
    Tamilmani Mohan

    Hello,
    You first need to ensure that driver is loaded correctly. So do not try anything from PHP (like sqlsrv_connect( $serverName, $connectionInfo);), until you see the "sqlsrv" in "Registered PHP Streams" when you navigate to the info.php (or whereever you make a call to phinfo() function).

    The steps are fairly easy and are very well explained in the Help file (.chm) that comes with driver installation.

    1. Figure out which version of PHP you are using(5.2.x or 5.3.x). The SQL Server Native drivers for SQL Server 2005/2008 are only working with PHP 5.2.4 or newer !!
    2. After knowing which version of driver you need, based on version of PHP, just copy that DLL file into the EXT subfolder of your PHP installation. I suppose that woule be c:\php5\ext
    3. Edit your php.ini file. It shall reside either in your c:\Windows or in your c:\php5 folder (again based on PHP installation). You may check whre this file is loaded from again from the PHP Info function output (phpinfo()), there is a line like this:
    Loaded Configuration File C:\php5\php.ini
    4. Once you edit your php.ini to load the appropriate file, restart your web server to make it reload the new php.ini
    5. Check again the output from phpinfo()!
    Repeat 1 to 4 until you see "sqlsvr" in "Registered PHP Streams" line of phpinfo() output.

    Your driver is not properly loaded, and you will not see any warnings for this (besides the Fatal Error for "call to undefined function") until you see "sqlsvr" as part of Registered PHP Streams  in the output of phpinfo().


    Hope this helps.
    • Proposed as answer by Anton StaykovMVP Monday, March 01, 2010 1:54 PM
    • Marked as answer by Yi-Lun Luo Thursday, March 04, 2010 9:40 AM
    Monday, March 01, 2010 1:54 PM

All replies

  • Hello, I don't know much about PHP. But apparently, you're using Windows Authentication, which is not supported in SQL Azure. You have to use SQL Authentication.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, February 26, 2010 3:44 AM
  • Hello,
    Actually the error comes from missing function, which shall be part of the extension! Are you sure you are modifing the correct php.ini and that you restart the WebServer (apache or WebSite in IIS) and/or application pool (in case of IIS) to make sure the changes in php.ini are reloaded. Please make a check by create a info.php file which contains:
    <?php
    phpinfo();
    ?>
    Make a request via web browser to that file and check what extensions are loaded.
    If your driver is loaded you shall be able to see eintire section sqlsrv looking something like this:

    sqlsrv

    sqlsrv supportenabled
    DirectiveLocal ValueMaster Value
    sqlsrv.LogSeverity 0 0
    sqlsrv.LogSubsystems 0 0
    sqlsrv.WarningsReturnAsErrors On On

    Additionally you shall be able to see "sqlsrv" in "registered streams" on the very first lines of phpinfo output:
        
    Registered PHP Streams      php, file, data, http, ftp, compress.zlib, zip, sqlsrv


    Please note theat version 1.0 of driver is no longer supported and you have to use version 1.1. And also not that there is specific version for PHP 5.2 and 5.3. Also there are Thread Safe and Non Thread Safe versions of each driver. Also a vc6 and vc9 versions of driver. So your driver must match the PHP version and ThreadSafety you are using. For me it was the php_sqlsrv_52_nts_vc6.dll. And this is the Non-Thread Safe driver for php 5.2 compiled with VC++6. Because I am using PHP 5.2.13 None-Thread Safe on Apache 2.2.14 all for Windows as you can guess.

    It is always good to take a look at ERROR LOGS of WebServer as it will give you very valuable information. At least you will see that the driver is not loading. Here is a line from my ERROR LOG:
    [Sat Feb 27 21:34:00 2010] [error] [client 192.168.3.4] <b>Warning</b>:  PHP Startup: Unable to load dynamic library 'F:\\wamp\\php5\\ext\\php_sqlsrv_52_ts_vc6.dll' - The specified module could not be found.\r, referer: http://mysite.com/info.php
    This was generated while I was trying to load the "TS" (the Thread Safe) version of the driver. Once I changed to Non-Thread Sage driver, everything worked fine.

    Once you make sure the driver is loaded, you may go further.
    Just note that when you are using SQL Azure (as this forum is for SQL Azure) you have to use SQL Server authentication, as Yi-Lun Luo suggested, and you can find it in the CHM help file how to use it:
    sqlsrv_connect( string $serverName [, array $connectionInfo])
    Where you have to add more stuff in your connectionInfo array.
    Something like:
    $connectionInfo = array( "Database"=>"your_db", "UID" => "your_user_for_azure_db", "PWD"=>"password_for_that_user");

    And, that the SQL Azure server could not be "(local)".
    However if you jsut want to connect to SQL Server 2008 using windows authentication, it will work!

    Hope this helps!
    Please mark as answer if this post was helpful enough.




    Saturday, February 27, 2010 7:56 PM
  • Hi ,

    I configured everything in properly . I don't get anything in my php info .So tell me the steps .


    Thanks
    Tamilmani Mohan
    Monday, March 01, 2010 5:17 AM
  • Now i am using this

    $serverName = "(local)";


    $uid = "username";
    $pwd = "password";

    $connectionInfo = array( "UID"=>$uid,
                             "PWD"=>$pwd,
                             "Database"=>"databasename");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn === false )
    {
         echo "Unable to connect. ";
         die( print_r( sqlsrv_errors(), true));
    }
    Monday, March 01, 2010 5:18 AM
  • Hi ,

    I configured everything in properly . I don't get anything in my php info .So tell me the steps .


    Thanks
    Tamilmani Mohan

    Hello,
    You first need to ensure that driver is loaded correctly. So do not try anything from PHP (like sqlsrv_connect( $serverName, $connectionInfo);), until you see the "sqlsrv" in "Registered PHP Streams" when you navigate to the info.php (or whereever you make a call to phinfo() function).

    The steps are fairly easy and are very well explained in the Help file (.chm) that comes with driver installation.

    1. Figure out which version of PHP you are using(5.2.x or 5.3.x). The SQL Server Native drivers for SQL Server 2005/2008 are only working with PHP 5.2.4 or newer !!
    2. After knowing which version of driver you need, based on version of PHP, just copy that DLL file into the EXT subfolder of your PHP installation. I suppose that woule be c:\php5\ext
    3. Edit your php.ini file. It shall reside either in your c:\Windows or in your c:\php5 folder (again based on PHP installation). You may check whre this file is loaded from again from the PHP Info function output (phpinfo()), there is a line like this:
    Loaded Configuration File C:\php5\php.ini
    4. Once you edit your php.ini to load the appropriate file, restart your web server to make it reload the new php.ini
    5. Check again the output from phpinfo()!
    Repeat 1 to 4 until you see "sqlsvr" in "Registered PHP Streams" line of phpinfo() output.

    Your driver is not properly loaded, and you will not see any warnings for this (besides the Fatal Error for "call to undefined function") until you see "sqlsvr" as part of Registered PHP Streams  in the output of phpinfo().


    Hope this helps.
    • Proposed as answer by Anton StaykovMVP Monday, March 01, 2010 1:54 PM
    • Marked as answer by Yi-Lun Luo Thursday, March 04, 2010 9:40 AM
    Monday, March 01, 2010 1:54 PM
  • Hi ,
    This is stephen Ngethe,
    I think the thing worth noting is that you have to include ONLY those driver you are to use e.g if you are to use php 5.2 with safe threads uses  php_sqlsrv_52_ts_vc6.dll  and in the php.ini you will add this line to extension list extension=php_sqlsrv_52_ts_vc6.dll be sure which dll to use from this site==> http://msdn.microsoft.com/en-us/library/cc296170%28SQL.90%29.aspx
    the phpinfo() should show

    sqlsrv

    sqlsrv support enabled
    Directive Local Value Master Value
    sqlsrv.LogSeverity 0 0
    sqlsrv.LogSubsystems 0 0
    sqlsrv.WarningsReturnAsErrors On On
    If the drivers are loaded else try some other like those with no thread safe
    Wednesday, April 07, 2010 5:45 AM
  • Hi ,

    I configured everything in properly . I don't get anything in my php info .So tell me the steps .


    Thanks
    Tamilmani Mohan

    Hello,
    You first need to ensure that driver is loaded correctly. So do not try anything from PHP (like sqlsrv_connect( $serverName, $connectionInfo);), until you see the "sqlsrv" in "Registered PHP Streams" when you navigate to the info.php (or whereever you make a call to phinfo() function).

    The steps are fairly easy and are very well explained in the Help file (.chm) that comes with driver installation.

    1. Figure out which version of PHP you are using(5.2.x or 5.3.x). The SQL Server Native drivers for SQL Server 2005/2008 are only working with PHP 5.2.4 or newer !!
    2. After knowing which version of driver you need, based on version of PHP, just copy that DLL file into the EXT subfolder of your PHP installation. I suppose that woule be c:\php5\ext
    3. Edit your php.ini file. It shall reside either in your c:\Windows or in your c:\php5 folder (again based on PHP installation). You may check whre this file is loaded from again from the PHP Info function output (phpinfo()), there is a line like this:
    Loaded Configuration File C:\php5\php.ini
    4. Once you edit your php.ini to load the appropriate file, restart your web server to make it reload the new php.ini
    5. Check again the output from phpinfo()!
    Repeat 1 to 4 until you see "sqlsvr" in "Registered PHP Streams" line of phpinfo() output.

    Your driver is not properly loaded, and you will not see any warnings for this (besides the Fatal Error for "call to undefined function") until you see "sqlsvr" as part of Registered PHP Streams in the output of phpinfo().


    Hope this helps.

    It's helpful to me, Thanks for your sharing!
    Thursday, February 10, 2011 11:08 PM
  • Hi,

    I have the same problem. The follow is information I copied from phpinfo() output.

    My OS is win7, and iis version is iis7.5, php version is 5.3.6 compiled by VC9 (not thread safe version).

     

    extension=php_sqlsrv_53_nts_vc9.dll

    extension=php_pdo_sqlsrv_53_nts_vc9.dll

     

    __________________________________________________________________________________________

    sqlsrv

    sqlsrv support enabled

    Directive Local Value Master Value
    sqlsrv.LogSeverity 0 0
    sqlsrv.LogSubsystems 0 0
    sqlsrv.WarningsReturnAsErrors On

    On

    Thursday, May 05, 2011 3:26 AM
  • hello

    i have the problem ::

    i am installing php5.3 and IIS and this lines in php.ini:

    extension=php_sqlsrv_53_nts_vc9.dll

    extension=php_pdo_sqlsrv_53_nts_vc9.dll

    and see this notification in phpinfo:                                                     

    sqlsrv support enabled

     

    Directive Local Value Master Value
    sqlsrv.LogSeverity 0 0
    sqlsrv.LogSubsystems 0 0

    sqlsrv.WarningsReturnAsErrors

     

     

    On

    On

    now i connect to database and not acknowledge 

    <?php

    $serverName = "SERVERNAME";
    $conn = sqlsrv_connect( $serverName, array("Database"=>"TESTDATABASE","CharacterSet"=>"UTF-8"));
    if($conn == false )
    die ("<b!! database no connect !!</b>");

    ?>

    this lines working correct in wamp and connect to database  but in IIS not connect in database.

    please help me.

    tank you

    Tuesday, January 03, 2012 4:47 AM