1

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.

enter image description here

Any help would be greatly appreciated.

Thanks,

Rich
  • 523
  • 2
  • 6
  • 19

2 Answers2

3

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

Community
  • 1
  • 1
Rich
  • 523
  • 2
  • 6
  • 19
  • Do you use SQlite or MySQL? – Roel Oct 21 '15 at 13:57
  • We use MySQL, can't remember why it needed sqlite, I think it is something todo with yii and the database functionality. – Rich Oct 23 '15 at 08:22
  • For me it happened that I needed also sqlite (not only mysql) because of cache functionality that was configured to use sqlite - which I initially overlooked (and lost too much time to search why this error). – Zbyszek Mar 08 '18 at 13:00
0

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.

taiff
  • 89
  • 8