douruoshen1449 2014-12-09 21:15
浏览 88
已采纳

Laravel PHPUnit PDOException异常

I don't know why when I run a PHPUnit test, I get the following error:

PDOException: SQLSTATE[HY000] [2002] No such file or directory

My testing environment database setting is:

return [

    'fetch' => PDO::FETCH_CLASS,

    'default' => 'mysql',

    'connections' => [
        'mysql' => [
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'clg_test',
            'username'  => 'root',
            'password'  => 'veryHardPass',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ]
    ],

    'migrations' => 'migrations',

];

The reason why I am using MySQL as oppose to SQLite is because my migration files use dropColumn which is not supported by SQLite. I call the migration via Artisan::call('migrate') in the setup.

If I actually call migration manually in the terminal via php artisan migrate --env=testing then the migration IS successful and the databases are created.

Why am I then facing the above problem?

  • 写回答

1条回答 默认 最新

  • dongsimang4036 2014-12-09 21:35
    关注

    Try changing localhost to 127.0.0.1. The message you're getting is indicative of the script not being able to connect to MySQL through a socket, but using an ip should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用