doqpm82240
2016-08-11 12:34
浏览 50
已采纳

通过php中的PDO将xampp连接到在线MSSQL数据库

I've installed xampp on my computer. When I try to connect it tells me

Error!: could not find driver

When I run my code on my webhost, it works.

Some info:

XAMPP 3.2.2
MSSQL Server 2012

I connect with the following code:

define("USER_NAME", "myusername");
define("DATABASE", "mydatabase");
define("PASSWORD", "mypassword");
define("HOST", "myhost");

try{
    $db = new PDO("dblib:host=".HOST.";dbname=".DATABASE, USER_NAME, PASSWORD);
    $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}catch(PDOException $exception){
    echo $exception->getMessage();
    exit;
}

I've downloaded these files, dropped them in the ext folder and added the following lines to php.ini:

extension=php_dblib.dll  
extension=php_sqlsrv_54_ts.dll  
extension=php_pdo_sqlsrv_54_ts.dll

图片转代码服务由CSDN问答提供 功能建议

我在我的电脑上安装了xampp。 当我尝试连接它时告诉我

错误!:找不到驱动程序

当我在我的虚拟主机上运行我的代码时,它可以工作。

一些信息:

XAMPP 3.2.2
MSSQL Server 2012

我使用以下代码连接:

  define(“USER_NAME”,“myusername”); 
define(“DATABASE”,“mydatabase”); \  ndefine(“PASSWORD”,“mypassword”); 
define(“HOST”,“myhost”); 
 
try {
 $ db = new PDO(“dblib:host =”。HOST。“; dbname =”  .DATABASE,USER_NAME,PASSWORD); 
 $ db-> setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION); 
} catch(PDOException $ exception){
 echo $ exception-> getMessage();  
退出; 
} 
   
 
 

我已下载这些文件,将它们放在ext文件夹中,并将以下行添加到php.ini:

  extension = php_dblib.dll 
extension = php_sqlsrv_54_ts.dll 
extension = p  hp_pdo_sqlsrv_54_ts.dll 
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsfsdfsdfsdf6455 2016-08-11 13:50
    已采纳

    Change this

    $db = new PDO("sqlsrv:Server=YouAddress;Database=YourDatabase", "Username", "Password"); 
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题