PHP pdo_sqlsrv extension installation tutorial
On the Windows platform, pdo_sqlsrv is available as a driver. This article will show you how to install the pdo_sqlsrv extension in your PHP so that you can access your SQL Server database.
You can download and use the pdo_sqlsrv extension from this document. The files provided here are suitable for PHP versions 5.6 - 7.3 on Windows operating systems.
If your PHP version is outside this range or your system is not Windows, you can find the driver that suits you here: https://www.microsoft.com/en-us/sql-server /developer-get-started/php-windows/.
Extract the downloaded pdo_sqlsrv driver to the ext folder in the directory where PHP is installed. The unzipped directory name may be slightly different, but should be similar to "php_pdo_sqlsrv_7_x_ts.dll".
Next, add the following two files to PHP’s php.ini file. If you cannot find the php.ini file, use the phpinfo() function to find the current php.ini path.
extension=php_sqlsrv_7_x_ts.dll (this line should be inserted before)
extension=php_pdo_sqlsrv_7_x_ts.dll
Note: When adding these lines, replace php_sqlsrv_7_x_ts.dll and php_pdo_sqlsrv_7_x_ts .dll filename to match the name of the file you downloaded.
Use the following command to check whether the driver was successfully installed:
if (!function_exists('sqlsrv_connect')) echo " Sqlsrv drivers not installed";
If installed successfully, the last statement will have no output. Otherwise, it will output "Sqlsrv drivers not installed".
If you are using PHP 5.x, use the corresponding version of the driver; if you are using PHP 7.x, use the corresponding version of drive.
If you encounter problems installing or configuring the pdo_sqlsrv driver, check the PHP error log file for more information about the problem.
When using the pdo_sqlsrv driver in PHP, the function names and method names are different from the SQL Server driver. Before processing the pdo_sqlsrv extension, review the SQL Server driver's function and method names.
In the PHP file, verify that the SQL Server authentication information is correct by using the following method:
$connectionInfo = array("UID" => $username, "PWD" => $ password, "Database" => $databaseName);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn) {
echo "Connection established.";
} else{
echo "Connection could not be established."; die(print_r(sqlsrv_errors(), true));
}
Summary
These are the steps required to install the pdo_sqlsrv extension. Hope this article is helpful to you. If you face any problem, please leave a message in the comment section below and we will try our best to answer your doubts.
The above is the detailed content of php pdosqlsrv installation. For more information, please follow other related articles on the PHP Chinese website!