You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XAMPP中修改php.ini添加SQL Server驱动后未生效,求解决方法

Fixing PDO_SQLSRV Not Loading in XAMPP 5.6.3 (PHP 5.6)

Hey there, let's troubleshoot why your PDO_SQLSRV driver isn't loading properly with XAMPP 5.6.3. First off, I suspect you meant PHP 5.6 instead of 5.16—since XAMPP 5.6.3 ships with PHP 5.6.x, that makes way more sense. Let's work through step-by-step fixes:

1. Verify Driver Version & Compatibility

  • Match PHP exactly: Make sure you downloaded the PDO_SQLSRV driver built specifically for PHP 5.6. The driver's version must align perfectly with your PHP major/minor release.
  • Thread Safety check: XAMPP 5.6.3 uses a thread-safe (TS) PHP build by default. Confirm your driver file ends with _ts.dll (which you have), and double-check PHP's thread safety status via phpinfo()—look for the "Thread Safety" field, it should say "enabled".
  • Architecture match: XAMPP 5.6.3 is typically 32-bit, so ensure you grabbed the x86 version of the driver, not x64.
  • ODBC Driver Dependency: PHP 5.6 requires the Microsoft ODBC Driver 11 for SQL Server (newer versions like ODBC 17+ don't support PHP 5.x). Install this first—without it, PDO_SQLSRV can't load at all.

2. Confirm You're Editing the Right php.ini

XAMPP has two common php.ini files, and mixing them up is a super common mistake:

  • Apache's php.ini (used for web requests): xampp/apache/bin/php.ini
  • CLI's php.ini (used for command-line scripts): xampp/php/php.ini

To confirm which one your web server uses:

  1. Create a phpinfo.php file in your XAMPP htdocs folder with this code:
    <?php phpinfo(); ?>
    
  2. Access it via your browser (e.g., http://localhost/phpinfo.php)
  3. Look for the Loaded Configuration File field—this shows the exact php.ini your Apache is using. Make sure you edited this one, not the CLI version.

3. Correct Extension Setup

  • Place driver in the right folder: Move PDO_Sqlsrv__56_ts.dll (double-check the filename—did you accidentally add an extra underscore?) into xampp/php/ext/ (this is PHP's default extension directory; confirm via the "extension_dir" field in phpinfo()).
  • Add the right extension line: In your target php.ini, add this line (ensure the filename matches exactly—Windows is case-insensitive, but matching avoids headaches):
    extension=PDO_Sqlsrv__56_ts.dll
    
    Note: Some PHP 5.6 builds expect the php_ prefix, so try extension=php_pdo_sqlsrv_56_ts.dll if the first line doesn't work.

4. Restart Apache & Validate

  • After making changes, fully restart the Apache service in XAMPP Control Panel—refreshing the browser won't apply php.ini changes.
  • Recheck phpinfo(): Search for "pdo_sqlsrv". If you see a dedicated section with driver details, it's loaded successfully.
  • If it still fails, check Apache's error log (xampp/apache/logs/error.log). It will tell you exactly why the driver didn't load—common issues include missing dependencies, wrong file path, or incompatible driver version.

5. Double-Check for Typos

Small mistakes break everything:

  • Did you misspell the driver filename in php.ini?
  • Is there an extra space or character in the extension line?
  • Did you forget to remove a leading semicolon (;)? Semicolons comment out lines in php.ini, so your extension line will be ignored if it starts with one.

内容的提问来源于stack exchange,提问作者shoaib Muhammad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:38:24