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

XAMPP/PHP报错:extension mysql is not compiled into PHP 求解决方案

Fixing "extension mysql is not compiled into PHP" in XAMPP

Hey there, let's get this sorted out for you! The core issue here is that the old mysql.dll extension was completely removed in PHP 7.0+, and modern XAMPP versions don't include it at all—so trying to enable it won't work, even if you uncomment that line in php.ini. Here's what you need to do instead:

Step 1: Remove the outdated extension=mysql.dll line

First, head back to your php.ini file and delete (or re-comment) the line extension=mysql.dll. Since this extension no longer exists in your XAMPP setup, keeping this line will only trigger unnecessary errors.

Step 2: Verify pdo_mysql is properly loaded

You mentioned seeing pdo_mysql.dll in the ext/ directory—let's confirm PHP is actually utilizing it:

  • Open php.ini and look for the line extension=pdo_mysql.dll (Windows) or extension=pdo_mysql (macOS/Linux). Make sure there's no leading semicolon (;) commenting it out.
  • Restart your Apache server from the XAMPP control panel.
  • Create a quick phpinfo.php file in your htdocs folder with this code:
    <?php phpinfo(); ?>
    
  • Access it in your browser (e.g., http://localhost/phpinfo.php) and search for "pdo_mysql". You should see a dedicated section confirming the extension is active.

Step 3: Update your PEAR DSN to use PDO-compatible syntax

Since you're using PEAR and a $dsn array, you need to adjust your DSN to work with PDO_MySQL instead of the deprecated mysql extension.

For example, if your old DSN looked like this:

$dsn = 'mysql://username:password@localhost/your_database';

Switch to the PDO-style DSN format:

$dsn = 'mysql:host=localhost;dbname=your_database;charset=utf8mb4';

If you're using PEAR's MDB2 library (a maintained alternative to the old PEAR DB), initialize the connection like this:

require_once 'MDB2.php';
$db = MDB2::connect($dsn, $options);

Key Reminder: The mysql extension is gone for good

PHP dropped support for the original mysql extension years ago due to security and obsolescence. All new (and updated) code should use either PDO_MySQL or mysqli instead. Since you already have pdo_mysql loaded, leaning into PDO is the smoothest path forward with your current setup.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:05:25