Wednesday, July 29, 2015

Access MySQL from LAMP Instance of Google App Engine with PHP

There are many who struggle to access MySQL database created in LAMP instance of Google App Engine.  Following is a sample PHP coding to do so.  You need to replace the values in Italics with your own.  The mistake many do is not using "" as the database host.


echo "<br>Connecting...";

$dbHost = "";
$dbUser = "username";
$dbPass = "password";
$dbName = "databasename";

$dbConnection = mysql_connect($dbHost, $dbUser, $dbPass);

if ($dbConnection) {
echo "<br>Connected";

if (mysql_select_db($dbName, $dbConnection)) {
echo "<br>Selected";

$dbQuery = "SELECT * FROM tablename";

if ($dbResult = mysql_query($dbQuery)) {
echo "<br>Reading";

while ($dbRow = mysql_fetch_array($dbResult)) {
$mField = $dbRow["fieldname"];

echo "<br>Read $mField";



No comments:

Post a Comment