Home > Backend Development > PHP Problem > php pdosqlsrv installation

php pdosqlsrv installation

PHPz
Release: 2023-05-07 12:24:07
Original
1312 people have browsed it

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.

  1. Download pdo_sqlsrv extension

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/.

  1. Unzip the extension and install

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.

  1. Testing the driver

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".

  1. Some details

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.";
Copy after login

} else{

echo "Connection could not be established.";
die(print_r(sqlsrv_errors(), true));
Copy after login

}

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template