php连接到服务器错误

时间:2012-08-04 03:06:33

标签: php connection

我最近将数据库迁移到了在线服务器。 我已经在php脚本中进行了必要的更改,以便从数据库中请求信息。

<?php
/*
* All database connection variables
*/
define('DB_USER', "******"); // db user
define('DB_PASSWORD', "******"); // db password (mention your db password here)
define('DB_DATABASE', "********"); // database name
define('DB_SERVER', "********"); // db server
?>

我正在使用3层连接数据库

<?php
/**
 * A class file to connect to database
 */
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());

    // Selecting 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();
}
}
?>

错误在于此文件。

<?php
// array for JSON response
$response = array();
header('Content-type: application/json');
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["UserID"])) {
$UserID = $_GET['UserID'];

// get a product from products table
$result = mysql_query("SELECT UserID, FirstName, LastName FROM Users WHERE UserID = $UserID") or die(mysql_error());

if (!empty($result)) {
    // check for empty result
    if (mysql_num_rows($result) > 0) {

        // user node
        $response["Users"] = array();

        While ($row = mysql_fetch_array($result)){

            $user[] = array();
            $user["UserID"] = $row["UserID"];
            $user["FirstName"] = $row["FirstName"];
            $user["LastName"] = $row["LastName"];


            array_push($response["Users"], $user);
        }



        // success
        $response["success"] = 1;

        // echoing JSON response
        echo json_encode($response);
    } else {
        // no product found
        $response["success"] = 0;
        $response["message"] = "No User found";

        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // no product found
    $response["success"] = 0;
    $response["message"] = "No User 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);
}
?>

我已经检查了错误日志,它跟踪到require_once __DIR__ . '/db_connect.php';任何人都可以告诉我如何解决错误? 我得到的错误是a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

0 个答案:

没有答案