PhpSQLServerAuthentication connection code. Php Tutorial SQLServerAuthentication connection code * $ serverName (local); database tutorial Server address $ uidpandao; database username $ pwd1987; database password php Tutorial SQL Server Authentication connection code
*/
$ ServerName = "(local)"; // address of the database tutorial server
$ Uid = "pandao"; // database username
$ Pwd = "1987"; // database password
$ ConnectionInfo = array ("UID" => $ uid, "PWD" => $ pwd, "Database" => "test ");
$ Conn = sqlsrv_connect ($ serverName, $ connectionInfo );
If ($ conn = false)
{
Echo "connection failed! ";
Die (print_r (sqlsrv_errors (), true ));
}
$ Query = sqlsrv_query ($ conn, "select top 10 nid, title, content FROM test. dbo. news ");
While ($ row = sqlsrv_fetch_array ($ query )){
Echo $ row ['nid']. "-----". $ row ['title']."
";
}
?>
Sqlserver2005 or sqlserver2008
Download the driver first
Http://www.microsoft.com/downloads/details.asptutorial X? FamilyId = 61BF87E0-D031-466B-B09A-6597C21A2E2A & displaylang = en
Decompress the downloaded file
Configuration:
1. put the decompressed php_sqlsrv.dll and php_sqlsrv_ts.dll in the PHP extension directory (PHPEXT ).
2. edit the php. ini file (in the windows folder) and add the following extensions:
Extension = php_sqlsrv.dll
Extension = php_sqlsrv_ts.dll
3. remove the semicolon before extension = php_mssql.dll.
SQL Server has two common Authentication methods: Windows Authentication and SQL Server Authentication ), the second authentication method must enable the hybrid mode of SQL Server.
1. Windows Authentication:
$ ServerName = "(local )";
$ ConnectionInfo = array ("Database" => "TestingInfo", "ConnectionPooling" => false );
$ Conn = sqlsrv_connect ($ serverName, $ connectionInfo );
If (! $ Conn ){
Echo "o no !!!!! ";
Die (print_r (sqlsrv_errors (), true ));
} Else {
Echo "yes done ";
}
?>
2. SQL Server Authentication:
$ ServerName = "(local )";
$ Uid = "dbusername"; // database username
$ Pwd = "dbuserpass"; // database user password
// The following Database is the Database name
$ ConnectionInfo = array ("UID" => $ uid, "PWD" => $ pwd, "Database" => "dbname ");
$ Conn = sqlsrv_connect ($ serverName, $ connectionInfo );
If (! $ Conn ){
Echo "o no !!!!!!! ";
Die (print_r (sqlsrv_errors (), true ));
} Else {
Echo "yes done ";
}
?>
Connecting SQL Server Authentication connection code */$ serverName = (local); // database tutorial Server address $ uid = pandao; // database username $ pwd = 1987; // database password...