Download Pdo_dblib Library
PDO's various libraries can be found in pecl, for example, MYSQL Library: Pdo_mysql, Oracle Library: Pdo_oci.
As a connection library for SQL Server, download pdo_dblib with the following command:
Copy Code code as follows:
wget Http://pecl.php.net/get/PDO_DBLIB
Installing the Pdo_dblib Library
After the download is complete, install through Pear:
Copy Code code as follows:
/usr/bin/pear Install Pdo_dblib-1.0.tgz
If the installation is successful,/usr/lib64/php/modules (non 64-bit host should be in/usr/lib/... The Pdo_dblib.so library (pictured below) is listed in the directory. The following need to combine the pdo_dblib.so Library with PHP, enter the/ETC/PHP.D and create a file named Pdo_dblib.ini. Write the following code in it:
Copy Code code as follows:
Restart the Apache service
Copy Code code as follows:
PHP test
Use a simple code to test whether you can connect MSSQL properly. When using PDO for different types of database access, you only need to modify the connection parameters in PDO () to be the same as other calling functions, so that different action functions will not be invoked when the database is developed.
Copy Code code as follows:
<?php
$db = new PDO ("Dblib:host=myhost;dbname=mydb", "MyUserName", "MyPassword");
$sql = "SELECT count (*) count from TestTable";
$res = $db->query ($sql);
while ($row = $res->fetch ()) {
Print_r ($row);
}
$res = null;
$DB = null;
?>