0
votes

We have had a PHP script using pdo code with a mySQL database all hosted on our ISP standard LAMP stack without any issues after running for weeks. Boss wants to deploy to Google App Engine and CloudSQL. CloudSQL is populated with same data. Ran it from the GAE dev implementation on the local machine pointing at mySQL and CloudSQL, and it works fine in both cases.

Upon deploying PHP code to GAE in the cloud and changing the pdo connection string to accommodate GAE-to-CloudSQL connection we get the following error:

Fatal error: Call to a member function fetchColumn() on a non-object...

include 'database.php';     //pdo connection with try|catch confirming connection.
$pdo = Database::connect(); //No problems here.  We have connection object.
$sql = "SELECT Count(CatalogID) FROM Catalog";
$rows = $pdo->query($sql)->fetchColumn(); //This is the line that throws the error.

Why does GAE handle differently?

Any solutions? (I would strongly prefer to not call rowCount() against a 'Select CatalogID from Catalog;'. There are too many records to bring back. Seems inefficient.)

1

1 Answers

0
votes

Found it. The query($sql) part was failing due to the $pdo not knowing which database in the CloudSQL instance was to be queried. The CloudSQL dashboard has a link "How to connect to your CloudSQL instance". Since I copy-and-pasted this connection code, I missed that it was missing the dbname component.

Google included the dbname portion in the mysqli section but not the pdo section of "How to connection to your CloudSQL instance".