Download the PDO_DBLIB Library
Various databases of PDO can be found in PECL, for example, MySQL database: PDO_MYSQL and Oracle Database: PDO_OCI.
As the SQL Server Connection Library, run the following command to download PDO_DBLIB:
Copy codeThe Code is as follows:
Wget http://pecl.php.net/get/PDO_DBLIB
Install the PDO_DBLIB Library
After the download is complete, install it through PEAR:
Copy codeThe Code is as follows:
/Usr/bin/pear install PDO_DBLIB-1.0.tgz
If the installation is successful, the/usr/lib64/php/modules (non-64-bit hosts should have more pdo_dblib.so libraries in the/usr/lib/...) Directory (for example ). Next we need to combine the pdo_dblib.so library with php to enter/etc/php. d and create a file named pdo_dblib.ini. Write the following code:
Copy codeThe Code is as follows:
Extension = pdo_dblib.so
Restart the Apache service
Copy codeThe Code is as follows:
Service httpd restart
PHP Testing
Use a simple piece of code to test whether MSSQL can be connected normally. When using PDO to access different types of databases, you only need to modify the connection parameters in PDO () to make other calling functions the same. In this way, different operation functions are not called because of different databases during development.
Copy codeThe Code is 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;
?>