我正在使用 php 和 mysql 来处理 web 开发示例,但问题是系统显示有关选择数据库的错误消息有人可以帮我解决这个问题吗???
客户端.js
function GetAllStudents()
{
var formRequest = new FormData();
formRequest.append('getStudents', "getAllStudents");
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", uploadComplete, false);
xhr.open("GET", 'StudentService/getAllStudents.php');
xhr.send(formRequest);
}
function GetStudentByID(id)
{
var formRequest = new FormData();
formRequest.append('sid', id);
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", uploadComplete, false);
xhr.open("POST", 'StudentService/getStudentByID.php');
xhr.send(formRequest);
}
function uploadComplete(evt)
{
console.log(evt.target.responseText);
}
代码1
<?php
require_once('../ConnectionManager.php');
$response = array();
$db = ConnectionManager::getInstance();
$result = mysql_query("SELECT * FROM student") or die("their was an error in table");
if(mysql_num_rows($result) >0)
{
$response["student"] = array();
while($row = mysql_fetch_array($result))
{
$student = array();
$student["ID"] = $row["ID"];
$student["Index"] = $row["Index"];
$student["Name"] = $row["Name"];
array_push($response["student"], $student);
}
$response["success"] = 1;
echo json_encode($response);
}
else
{
$response["success"] = 0;
$response["message"] = "No Students Found!!";
echo json_encode($response);
}
?>
代码2
<?php
require_once 'Connection.php';
class ConnectionManager
{
static $connection = null;
public static function getInstance()
{
if(ConnectionManager::$connection = null)
ConnectionManager::$connection = new Connection();
return ConnectionManager::$connection;
}
private function __construct()
{
}
private function __clone()
{
}
}
?>
代码3
<?php
class Connection
{
function __construct()
{
$this->connect();
}
function __destruct()
{
$this->close();
}
function connect()
{
require_once('db_config.php');
$connection = mysql_connect(SERVER, USER, PASSWORD) or die(mysql_error());
$dbConnect = mysql_select_db(DATABASE) or die("their was an error in the databse!!!");
return $connection;
}
function close()
{
mysql_close();
}
}
?>
系统显示错误信息
他们是表中的错误