如何使用xampp将sql server与php连接? [英] How to connect sql server with php using xampp?
问题描述
我正在尝试使用Xampp将SQL Server与PHP连接起来.我已经在ext文件夹中上传了dll文件,但无法连接它. 我的PHP版本是7.2.6. 上传的dll文件为-php_pdo_sqlsrv_72_ts.dll,php_sqlsrv_72_ts.dll. 我已经编写了这段代码以将我的SQL数据库与PHP-
I am trying to connect my SQL server with PHP using Xampp. I have already uploaded dll files in the ext folder but I am unable to connect it. My PHP version is 7.2.6. Uploaded dll files are - php_pdo_sqlsrv_72_ts.dll, php_sqlsrv_72_ts.dll. I have written this code to connect my SQL database with PHP-
<?php
$serverName = "INDO-SERV\SQLEXPRESS,1443";
$uid = "sa";
$pwd = "XXXXXX";
$databaseName = "web";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>$databaseName);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_close( $conn);
?>
尝试此操作时出现此错误-
I am getting this error when I had tried this-
致命错误:未捕获错误:调用未定义函数 C:\ xampp \ htdocs \ biometric \ db.php:7中的sqlsrv_connect()堆栈跟踪:#0 {main}在第7行的C:\ xampp \ htdocs \ biometric \ db.php中抛出.
Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\biometric\db.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\biometric\db.php on line 7.
任何人都知道我做错了什么或如何连接数据库.
Anyone has an idea where I am doing wrong or how to connect with the database.
推荐答案
可以按照以下步骤为SQL Server安装PHP驱动程序(sqlsrv
和/或pdo_sqlsrv
PHP扩展):
Installation of PHP Driver for SQL Server (sqlsrv
and/or pdo_sqlsrv
PHP extensions) can be done following the next steps:
- Based on Microsoft PHP Drivers for SQL Server Support Matrix download appropriate version of this driver. In your case - version 5.2 or 5.3 (32-bit or 64-bit also depends on PHP version).
- Download and install an appropriate ODBC driver - see System Requirements for the Microsoft Drivers for PHP for SQL Server
- Load PHP Driver for SQL Server as PHP extension.
- Restart Apache
使用<?php phpinfo();?>
检查配置.应该有一个名为pdo_sqlsrv
(如果使用PDO)和/或sqlsrv
(不带PDO)的部分.
Check the configuration with <?php phpinfo();?>
. There should be a section with name pdo_sqlsrv
(if you use PDO) and/or sqlsrv
(without PDO).
这篇关于如何使用xampp将sql server与php连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!