我正在尝试通过一个托管在123-reg上的php页面建立与MySql数据库的连接。 PHP页面是“http://domainName.biz/android_connect/get_all_bars.php”,当前页面出现空白?
该页面的代码如下:
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
$result = mysql_query("SELECT *FROM pubbar");
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["pubbar"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$pubbar = array();
$pubbar["Pubbar_ID"] = $row["Pubbar_ID"];
$pubbar["Pubbar_Name"] = $row["Pubbar_Name"];
$pubbar["Pubbar_AddressLine1"] = $row["Pubbar_AddressLine1"];
$pubbar["Pubbar_AddressLine2"] = $row["Pubbar_AddressLine2"];
$pubbar["Pubbar_LocationID"] = $row["Pubbar_LocationID"];
$pubbar["Pubbar_Postcode"] = $row["Pubbar_Postcode"];
$pubbar["Pubbar_Latitude"] = $row["Pubbar_Latitude"];
$pubbar["Pubbar_Longitude"] = $row["Pubbar_Longitude"];
$pubbar["Pubbar_TypeID"] = $row["Pubbar_TypeID"];
$pubbar["Pubbar_DateCreated"] = $row["Pubbar_DateCreated"];
$pubbar["Pubbar_DateModified"] = $row["Pubbar_DateModified"];
// push single product into final response array
array_push($response["pubbar"], $pubbar);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No bars found";
// echo no users JSON
echo json_encode($response);
}
此代码适用于我电脑上的本地WAMP服务器
正如您在顶部所见,它连接到另一个名为“db_connect.php”的PHP页面,其代码如下:
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
再次在我的本地WAMP服务器数据库上工作。这也连接到另一个名为“db_config.php”的PHP页面,其代码如下:
<?php
/*
* All database connection variables
*/
define('DB_USER', "<USER>"); // db user
define('DB_PASSWORD', "<PASSWORD>"); // db password (mention your db password here)
define('DB_DATABASE', "<DATABASE>"); // database name
define('DB_SERVER', "cust-mysql-X-X"); // db server
?>
如上所述,我有一个用于测试使用情况的wamp服务器设置,所有这些功能都是通过它预期的。但是现在我希望将它放在我的服务器上,因此我的应用程序Android应用程序可以永久访问它,并且get_all_bars.php页面显示为空白。我已经乱搞并改变了我认为可能需要更改的代码但不幸的是页面仍然是空白的。之前我和他们交谈过,配置数据,即用户名,密码等都是正确的,但我无法弄清楚其余代码中可能出现的问题。