我有 dbc.inc.php 文件。它里面有连接函数将我连接到数据库。在 test.inc.php 文件中,我在“Test”类中有 runQuery 函数。“Test”类扩展自 dbc.inc.php 文件中分配的“Dbc”类。
runQuery($db, $sql) 运行查询。但是,如果发生错误或警告,他不会显示错误。我相信我有一个语法错误。
为了测试兴趣,我在 $sql 语句中给出了错误的字段名。错误正在发生但未显示。
dbc.inc.php
<?php
class Dbc{
private $serverName;
private $userName;
private $password;
protected function connect($dbName = NULL){
$this->serverName = "localhost";
$this->userName = "root";
$this->password = "";
$conn = new mysqli($this->serverName, $this->userName, $this->password, $dbName);
if (!$conn) {
die("<h3>Error Connecting to the Database.</h3><h4 style=\"color: red\">". $conn->connect_error . "</h4>");
} else {
return $conn;
}
}
}
?>
测试.inc.php
<?php
require 'dbc.inc.php';
class Test extends Dbc{
function runQuery($db, $sql){
$query = mysqli_query($this->connect($db), $sql);
if (!$query) {
echo "no Query";
echo $this->connect($db)->connect_error;
return 0;
} else {
echo "Query EXEC";
return 1;
}
}
}
?>
测试代码
$conn = new Test;
$conn->runQuery("tch_phn", "UPDATE `employee` SET `uiS`='Assad' WHERE `uid`='Assad' ");
错误是我给出了一个未知的字段名称(uiS必须是uid)。我怎样才能做到这一点?
慕慕森