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

Yii2迁移报错:Could not find driver 问题求助

Troubleshooting Yii2 Migration Failure on XAMPP

Hey there, let's work through this migration issue you're hitting with Yii2 Advanced Template on your XAMPP setup. Looking at your error stack trace, the problem starts when Yii tries to connect to the database and load the migration table schema—so we'll focus on database connectivity and related extensions first.

Step 1: Verify Basic Database Setup

First, let's rule out the simplest issues:

  • Check if MySQL is running: Open your XAMPP control panel and make sure the MySQL module is started (status should show "Running").
  • Confirm the database exists: Yii migrations don't automatically create your database. Head to phpMyAdmin (via XAMPP control panel) and check if the hopordrop database is already created. If not, create it manually first.
  • Validate credentials: Double-check that your root username and empty password are correct. XAMPP defaults to an empty root password, but if you've ever modified it, update your common/config/main-local.php accordingly.

Step 2: Enable the Missing PDO MySQL Extension

Looking at your php -m output, I notice you have mysqlnd but no pdo_mysql extension—and Yii2 relies on PDO for database connections. This is almost certainly a key issue. Here's how to fix it:

  1. Open your XAMPP PHP configuration file: In the XAMPP control panel, click "Config" next to Apache, then select php.ini.
  2. Find the line that says ;extension=pdo_mysql (it might be ;extension=php_pdo_mysql.dll on Windows).
  3. Remove the leading semicolon (;) to uncomment the line.
  4. Save the file, then restart both Apache and MySQL services from the XAMPP control panel.
  5. Run php -m again in your terminal—you should now see pdo_mysql listed under PHP Modules.

Step 3: Test Direct Database Connection

To confirm your database credentials and extension are working, create a quick test script:

  1. In your project's frontend/web folder, create a file named test-db.php with this code:
    <?php
    $dsn = 'mysql:host=127.0.0.1;dbname=hopordrop';
    $username = 'root';
    $password = '';
    try {
        $pdo = new PDO($dsn, $username, $password);
        echo "✅ Database connection successful!";
    } catch (PDOException $e) {
        echo "❌ Connection failed: " . $e->getMessage();
    }
    
  2. Access this file via your browser (e.g., http://localhost/hoppordropp/frontend/web/test-db.php). If it fails, the error message will give you specific details (like wrong password, missing database, etc.).

Step 4: Ensure You're Running Migrations Correctly

  • Make sure you're executing the migration command from your project root directory (where the yii console script is located). The command should be:
    php yii migrate
    
  • For Yii2 Advanced Template, if you're working in a specific environment (like dev), you can specify it explicitly:
    php yii migrate --env=dev
    

Once you've worked through these steps, try running the migration command again. Most likely, enabling pdo_mysql and confirming your database exists will resolve the issue.


内容的提问来源于stack exchange,提问作者Miloš Vukadinović

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:42:29