问题
I'm having an issue with Yii and a mysql database running on Google Cloud sql.
Quick overview:
We have moved this from an existing server where it all worked with no issues at all and have now set up a Google Compute Engine server with php and all the relivant drivers mysql_pdo being one of them. We also have a Google Cloud SQL database storing all of our existing database information.
What I have tried
I have written a simple php script which uses
PDO('mysql:<IPADDRESS>;dbname=<MYDBNAME>,'MYUSERNAME','MYPASSWORD');
and this connects absolutely fine and can read tables and return data.
The Issue
As soon as I do the same in yii in the config/main.php it does not seem to work and get the error: CDbConnection failed to open the DB connection: could not find driver
Here is the yii connection string
'db'=>array(
'connectionString' =>'mysql:host=my.server.ip.address;dbname=my_db_name',
'emulatePrepare' => true,
'username' => 'my_username',
'password' => 'my_passsword',
'charset' => 'utf8',
),
I've also run the yii requirements script and it all returns as passed for the mysql PDO functions.
Any help would be greatly appreciated.
Thanks,
回答1:
Aha answering my own question:
The server needs to have sqlite PDO extension as well as the MySQL PDO extension. And now all working perfectly!
So it's worthwhile checking you phpinfo for this
You can add it according to this answer: https://superuser.com/a/320914
or via your php.ini uncomment the following:
extension=php_pdo_sqlite.dll
extension=php_sqlite.dll
Hope this helps other people
回答2:
Not sure if this could be related... I had "Permission Denied" issues connecting to Cloud SQL via a CentOS 7 GCE.
Found out it had to do with SELinux and found the following solution: Connect DATABASE Error TYPE: 2002: Permission denied
Basically setsebool -P httpd_can_network_connect_db 1
That solved my problem without disabling SELinux.
Hope it helps whoever reads this.
来源:https://stackoverflow.com/questions/24554980/yii-cdbconnection-failed-to-open-the-db-connection-could-not-find-driver-with-g