laravel 5连接MySQL,Laravel 5.1-连接到MySQL数据库(MAMP)

There are topics online that are discussing this problem however, I couldn't find any tidy explanation of the problem or any solid answers for the question. What I am trying to achieve is connecting Laravel 5.1 to MySQL Database of MAMP.

In my config>app.php:

'default' => env('DB_CONNECTION', 'mysql'),

'mysql' => [

'driver' => 'mysql',

'host' => 'localhost:8889',

'database' => 'test',

'username' => 'root',

'password' => 'root',

'charset' => 'utf8',

'collation' => 'utf8_unicode_ci',

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',

'prefix' => '',

'strict' => false,

],

In my .env:

DB_HOST=localhost

DB_DATABASE=test

DB_USERNAME=root

DB_PASSWORD=root

I also have .env.example: (which I believe has no functionality)

DB_HOST=localhost

DB_DATABASE=homestead

DB_USERNAME=homestead

DB_PASSWORD=secret

I also have create_users_table.php and create_password_resets_table.php in my database>migrations (even though I did not run any migration:make)

MAMP is directing and running the server successfully as it loads the project on localhost.

Here is my MAMP settings:

fab163901aa8de7cc43f5e888d8e2d8c.png

b85e69e58cb3156960b2afc0f02b15b8.png

And the test database is created (with tables in it which I have previously created and used in my other projects, not Laravel.)

d314281ba1b1f5bde836902052fe376a.png

Even though everything seems correct to me, when trying to submit Auth form, I am getting this error:

PDOException in Connector.php line 50:

could not find driver

in Connector.php line 50

at PDO->__construct ('mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=test', 'root', 'root', array('0', '2', '0', false, false)) in Connector.php line 50

at Connector->createConnection('mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=test', array('driver' => 'mysql', 'host' => 'localhost:8889', 'database' => 'test', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', 'prefix' => '', 'strict' => false, 'name' => 'mysql'), array('0', '2', '0', false, false)) in MySqlConnector.php line 22

and so on...

解决方案

Found my answer. Here is a way to fix it:

Start MAMP

On the top left, go to "MAMP" -> "Preferences"

Go to the "PHP" tab

Tick PHP 5.5.17 (or whatever you have) instead of the one which is ticked by default (5.6.1 -> 5.5.17 with he latest version of MAMP)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值