Pergunta

I am trying to connect Azure database with PHP. I installed sqlsrv driver. It also appears in phpinfo as PDO drivers = mysql, sqlite, sqlsrv.

However, the below code is not working:

$serverName = "xduuewepx4.database.windows.net";

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

                           "UID" => "intelligaia",

                           "PWD" => "Maporamic7",

                           "MultipleActiveResultSets" => false);

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

if($conn === false)

{

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

}

The reported error is:

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

Looking for your support.

Foi útil?

Solução

mmm, you better use odbc, make sure you have the azure odbc driver

here are some examples (goto start -> run -> enter odbcad32.exe and create a dsn(system or user) then in php you do

<?php
$connection = odbc_connect("DSN=TheNameYouHadEnterd",$username,$password);

$r_Results = odbc_exec($connection, "SELECT * FROM Table");

while($Row = odbc_fetch_array($r_Results)){
  var_dump($Row);
}

watch out with the while it is UNTESTED

Álvaro G. Vicario is right, ms provids this native drivers if you think you might ever migrate to another db(and you will) you should use pdo. her are:documentation and download but i would use the community edision(unless you are paying for support)

Outras dicas

The SQLSRV driver has two interfaces. If you want to use the PDO driver, you have to use regular PDO functions; the sqlsrv_connect() connect function belongs to the other API you are not planning to use.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top