Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Call to undefined function sqlsrv_connect()" when trying to connect to Azure DB from PHP

I'm trying to connect from php to Azure DB by

$connectionInfo = array("UID" => "xxx@xxx", "pwd" => "xxx", "Database" => "xxx");
$serverName = "tcp:xxx.database.windows.net,1433";
$conn = sqlsrv_connect($serverName, $connectionInfo);

But it gives me

Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www...\index.php on line 19

like image 904
Roger Avatar asked Oct 31 '11 11:10

Roger


1 Answers

you have to use the SQL Server native driver for php at first place, then you can do something like:

$serverName = "tcp:sample.database.windows.net, 1433";

$connectionOptions = array("Database" => "sampleInit", 

                           "UID" => "sampleUsr@sample",

                           "PWD" => "samplePass",

                           "MultipleActiveResultSets" => false);

$conn = sqlsrv_connect($serverName, $connectionOptions);

if($conn === false)

{

     die(print_r(sqlsrv_errors(), true));

}

You can read more on PHP and SQL Azure at following blog post:
http://blogs.msdn.com/b/brian_swan/archive/2010/02/12/getting-started-with-php-and-sql-azure.aspx

like image 96
astaykov Avatar answered Sep 30 '22 03:09

astaykov