我的 php 版本是 5.2,这是旧版本。这是因为我使用免费服务器它是我的网站http://driverrecord.hostzi.com/android_login_api/include/profile.php?username=4
我希望有一个人可以帮助我。问题可能与代码有关。
错误信息:
警告:mysql_query() [function.mysql-query]:第 20 行 /home/a6578726/public_html/android_login_api/include/profile.php 中的用户 'a6578726'@'localhost'(使用密码:NO)的访问被拒绝
配置文件.php
// array for JSON response
$response = array();
// include db connect class
require_once dirname(__FILE__). '/DB_Connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["username"])) {
$username = $_GET['username'];
// get a product from products table
$result = mysql_query("SELECT * FROM user WHERE user_id = $username");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$username = array();
$username["username"] = $result["user_id"];
$username["first_name"] = $result["first_name"];
$username["last_name"] = $result["last_name"];
$username["email"] = $result["email"];
$username["tel"] = $result["tel"];
$username["age"] = $result["age"];
$username["gender"] = $result["gender"];
// success
$response["success"] = 1;
// user node
$response["username"] = array();
array_push($response["username"], $username);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
DB_Connect.php
class DB_Connect {
// constructor
function __construct() {
}
// destructor
function __destruct() {
// $this->close();
}
// Connecting to database
public function connect() {
require_once 'include/config.php';
// connecting to mysql
$con = mysql_connect("XXXXXwebhost.com", "a6578726_driver", "abcde");
// selecting database
mysql_select_db(DB_DATABASE);
// return database handler
return $con;
}
// Closing database connection
public function close() {
mysql_close();
}
}
?>
配置文件
<?php
/**
* Database config variables
*/
define("DB_HOST", "XXXXwebhost.com");
define("DB_USER", "a6578726_driver");
define("DB_PASSWORD", "abcde");
define("DB_DATABASE", "a6578726_driver");
?>