【问题标题】:PHP PDO could'nt not find driverPHP PDO 找不到驱动程序
【发布时间】:2016-02-04 03:59:38
【问题描述】:

我在环境中使用 PDO 时遇到 PDO cannot find driver 错误。我在 Mac 上使用 xamp。

我已经知道问题所在,我已经使用 homebrew install 安装了 freetds,并使用以下命令成功连接到 azure mssql 服务器

tsql -H 234fddfg.database.windows.net -p 1433 -U dbuser -P db123!

但我不知道下一步该做什么。

我已经尝试了下面的 php 代码,但我仍然遇到同样的错误。

$dbh = new PDO("sqlsrv:Server=localhost;Database=mydb", "dbuser", "db123");

【问题讨论】:

    标签: php sql-server azure pdo


    【解决方案1】:

    需要为此安装 Microsoft SQL Server for PHP 驱动程序。

    点击此链接: https://www.microsoft.com/en-in/download/details.aspx?id=20098

    Perform the following steps to download and install the Microsoft Drivers for PHP for SQL Server (example below for 3.2 version):
    1. Download SQLSRV32.EXE to a temporary directory
    2. Run SQLSRV32.EXE
    3. When prompted, enter the path to the PHP extensions directory
    4. After extracting the files, read the Installation section of the SQLSRV32_Readme.htm file for next steps
    

    现在只需在您的 PHP.ini 中添加以下行(这是 PHP 的非线程安全版本,当您安装 PHP 以使用 IIS FastCGI 时,您最有可能使用它,我们建议您这样做):

    extension=php_sqlsrv.dll
    
    
    And Restart server
    

    【讨论】:

    • 您不能在 Windows 以外的任何设备上运行 SQLSRV 扩展,如此处所述:msdn.microsoft.com/en-us/library/cc296170.aspx 这里没有 mac 的 where 引用。另请参阅stackoverflow.com/questions/12489406/sqlserv-extension-on-mac
    • 那么解决办法是什么?
    • 在 Windows 7 或 8 或 8.1 或 10 上运行您的应用程序,无论您拥有哪个版本的 Windows。然后根据要求安装apache、php、mysql。这是我作为开发人员使用的,因为它可以帮助我使用 php 进行开发,并在需要时使用 sql server 与 php 连接。
    • 除了上面的注释,要安装windows,如果你不想格式化你的机器或者不想使用其他机器,你可以随时使用virtualbox或者vmware player来创建windows虚拟机.
    【解决方案2】:

    你有没有安装PDO_DBLIB,好像在OSX中,我们需要利用PDO_DBLIB作为pdo驱动连接MS SQL,例如

    $pdo = new PDO("dblib:host=$dbhost;dbname=$dbname", "$dbuser","$dbpwd");

    您可以参考Configure PHP environment on Mac to connect to SQL Server using PDO interface了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 2019-10-17
      • 2016-08-05
      • 2017-11-07
      • 2016-03-26
      相关资源
      最近更新 更多