通过 php-pdo 连接到 MSSQL 服务器? [英] Connecting to MSSQL server via php-pdo?

查看:49
本文介绍了通过 php-pdo 连接到 MSSQL 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法连接到 smarterasp.net 域上的 MSSQL 数据库.我正在使用:

I'm unable to connect to MSSQL database on smarterasp.net domain. I'm using:

Visual Studio 的 PHP 工具

PHP Tools for Visual Studio

代码如下:

<?php
 try {
     $conn = new PDO("mssql:host=host_name_string;dbname=database_name_string", "username_string", "password_string");

     // set the PDO error mode to exception
     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     echo "Connected successfully"; 
 }
 catch(PDOException $e)
 {
     echo "Connection failed: " . $e->getMessage();
 }

?>

以及被 PDOexception 类捕获的错误:

and the error caught by the PDOexception class:

连接失败:找不到驱动

我也在线测试了我的代码,再次得到同样的错误(在线测试者网址:http://sandbox.onlinephpfunctions.com).

I've also tested my code online and again getting the same error(online tester url: http://sandbox.onlinephpfunctions.com).

我已经搜索了解决方案,唯一可以解决我的问题的是取消注释:

I've searched for the solution and the only thing that could resolve my problem is by uncommenting:

extension=php_pdo_mysql.dll

extension=php_pdo_mysql.dll

但该行默认已取消注释.

but the line is already uncommented by default.

以下不能解决我的问题(而不是 mssql:host)

The following does not ressolve my problem (instead of mssql:host)

  • sqlsrv:host
  • dblib:host

推荐答案

您的问题是您的机器上没有安装 sql server 客户端或 Microsoft pdo 驱动程序.请这样做并确保您可以通过 udp 文件进行连接.

Your problem is that you have not installed either the sql server client or the Microsoft pdo drivers on your machine. Please do that and make sure you can connect via a udp file.

搜索 SQL 服务器客户端安装和 Microsoft pdo 驱动程序

Search SQL server client install and Microsoft pdo drivers

这篇关于通过 php-pdo 连接到 MSSQL 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆