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

通过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
  • 写回答

1条回答 默认 最新

  • dsfsdfsdfsdf6455 2016-08-11 13:50
    关注

    Change this

    $db = new PDO("sqlsrv:Server=YouAddress;Database=YourDatabase", "Username", "Password"); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 overleaf中论文编辑,报错`pages' is a missing field, not a string, for entry 4
  • ¥15 vhdl+MODELSIM
  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么