laravel 5连接MySQL,如何使用Laravel 5.3通过SSL连接到MySQL数据库

I've been searching all over the internet and haven't had any success.

I'm trying to connect to an azure mysql database over ssl from my laravel application.

I've confirmed I can connect to the database if I turn ssl off. So the settings are correct. What trips me up, and what I can find no documentation on is how to connect via ssl. I've got a sslkey - which I've confirmed can be used to to connect to the database with one of my database management programs - so the pieces are there.

Laravel, however, seems to be failing.

Here's my database driver:

'mysql' => [

'driver' => 'mysql',

'host' => env('DB_HOST', 'localhost'),

'port' => env('DB_PORT', '3306'),

'database' => env('DB_DATABASE', 'forge'),

'username' => env('DB_USERNAME', 'forge'),

'password' => env('DB_PASSWORD', ''),

'charset' => 'utf8',

'collation' => 'utf8_unicode_ci',

'prefix' => '',

'strict' => false,

'engine' => null,

'sslmode' => env('DB_SSLMODE', 'prefer'),

'options' => array(

PDO::MYSQL_ATTR_SSL_KEY => '\ssl\DatabaseCACert.pem'),

],

What am I missing? The database is just refusing the connection at the moment. SQLSTATE[HY000] [2002] So it's close.

解决方案

You need to provide the full path to the files. If they're in your laravel application folder then you can use the base_path method to generate the full poth. You may also need to define the cert and ca.

'options' => [

PDO::MYSQL_ATTR_SSL_KEY => base_path('ssl/client-key.pem'),

PDO::MYSQL_ATTR_SSL_CERT => base_path('ssl/client-cert.pem'),

PDO::MYSQL_ATTR_SSL_CA => base_path('ssl/ca-cert.pem')

]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值