se connecter à la database mssql via sqlsrv_connect () – PHP

Je tente de me connecter à une database Microsoft SQL 2005 en utilisant PHP en utilisant la fonction sqlsrv_connect() . hélas, la fonction renvoie false, et je ne sais pas pourquoi.

 <?php $myServer = "MAZE.jpc.wa.edu.au.local"; $myUser = "myUsername"; $myPass = "myPassword"; $myDB = "John Paul College"; $connectionInfo = array("Database"=>$myDB, "UID" => $myUser, "PWD" => $myPass); $conn = sqlsrv_connect($myServer, $connectionInfo); //returns false if( $conn === false ) { echo "failed connection"; } $sql = "SELECT name FROM users WHERE name= 'admin'"; $stmt = sqlsrv_query($conn,$sql); if(sqlsrv_fetch($stmt) ===false) { echo "couldn't fetch data"; } $name = sqlsrv_get_field($stmt,0); echo $name; sqlsrv_close( $conn ); ?> 

Est-ce que quelqu'un sait pourquoi je ne peux pas me connecter? Merci.

Modifier.

Ok, eh bien, j'ai été capable d'afficher un message d'erreur grâce à la réponse des autres gars, qui déclare

 Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires either the Microsoft SQL Server 2008 Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native Client ODBC Driver to communicate with SQL Server. Neither of those ODBC Drivers are currently installed. Access the following URL to download the Microsoft SQL Server 2008 R2 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires either the Microsoft SQL Server 2008 Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native Client ODBC Driver to communicate with SQL Server. Neither of those ODBC Drivers are currently installed. Access the following URL to download the Microsoft SQL Server 2008 R2 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) ) 

Je ne suis pas entièrement sûr de savoir comment résoudre ce problème. J'utilise XAMPP comme mon server web de test, php version 5.3 et le suivant .dlls php_sqlsrv_53_ts_vc6.dll et php_pdo_sqlsrv_53_ts_vc6.dll

Je suggère que vous affichiez l'erreur de connection en utilisant sqlsrv_errors (). S'il vous plaît voir la mise en œuvre suivante.

 <?php $serverName = "serverName\sqlexpress"; //serverName\instanceName // Since UID and PWD are not specified in the $connectionInfo array, // The connection will be attempted using Windows Authentication. $connectionInfo = array( "Database"=>"dbName"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } ?> 

Pour plus d'informations: http://php.net/manual/fr/function.sqlsrv-connect.php

Téléchargez le SQL Native Client comme le suggère le message d'erreur. Cela est distinct de SQL Server et une condition pour que ce pilote fonctionne correctement. Leçon tirée de la construction d'une implémentation de sqlsrv dans un environnement IIS