SQLSTATE [HY000] [2002]连接仅在使用laravel 5的工匠中被拒绝

I'm running a vagrant box and with laravel 5. For some reason when running php artisan it throws the following error:

SQLSTATE[HY000] [2002] Connection refused

This happens when I have my host set to 127.0.0.1. When using localhost I get File or directory not found.

The strange part is that the website itself works fine in the browser. This only happens in php artisan.

I also tried changing ports between 3306 and 33060.

Any ideas?

EDIT: I did the following in the laravel index.php file:

$pdo = new PDO('mysql:host=127.0.0.1;dbname=mydb','root','mypassword');
var_dump(get_class_methods($pdo));
die();

and it worked fine. Inside the Connector.php file I checked the variables being passed to the PDO constructor and they were identical to what I filled in above. What is going on?

查看全部
doukun8670
doukun8670
2015/07/05 12:09
  • laravel
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复