简体   繁体   English

在 php 7.2 中启用 pdo_sqlsrv,不起作用

[英]enable pdo_sqlsrv in php 7.2, not working

I have followed all the guided path,我已经遵循了所有的引导路径,

  1. download the appropriate sql driver for php 7.2 from https://github.com/Microsoft/msphpsql/releaseshttps://github.com/Microsoft/msphpsql/releases为 php 7.2 下载适当的 sql 驱动程序
  2. copy and past the ts files to my xampp/php/ext folder,将 ts 文件复制并粘贴到我的 xampp/php/ext 文件夹中,
  3. enabled the extension from php.ini file从 php.ini 文件启用扩展
  4. Restart the xampp and check php info but I couldn't see the extension enabled in phpinfo重新启动 xampp 并检查 php 信息,但我看不到 phpinfo 中启用的扩展在此处输入图像描述

I need to know, is it the version issue or I missed out something.我需要知道,是版本问题还是我错过了什么。

  1. You need to run as an administrator.您需要以管理员身份运行。
  2. An ODBC driver is missing.缺少 ODBC 驱动程序。

Installation of PHP Driver for SQL Server can be done following the next steps:可以按照以下步骤安装 SQL Server 的 PHP 驱动程序:

Example:例子:

<?php
# Info
$server   = 'server\instance,port';
$database = 'database';
$username = 'username';
$password = 'password';

# Connect
try {
    $conn = new PDO("sqlsrv:server=$server;Database=$database", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    die("Error connecting to SQL Server".$e->getMessage());
}

# End
echo 'Connected';
$conn = null;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM