示例测试查询代码中出现错误。 但是在运行时,我遇到以下错误
(!)致命错误:未捕获的错误:在行
的D:\ dev \ workspace \ web \ StartUp1 \ index.php中找不到类'Db'我正在使用wampserver和php ver:7.2.10
index.php文件中的代码:
<html>
<body>
<?php
require_once ('db.php');
require_once ('common.php');
require_once ('config.php');
$db= new Db();
$records = $db->query("SELECT * FROM x_note LEFT OUTER JOIN x_user ON
x_note.user_id=x_user.user_id");
dump($records);
?>
</body>
</html>
和DB.php文件:
<?
class Db {
private $connection;
public function __construct($option = null){
if ($option != null){
$host = $option['host'];
$user = $option['user'];
$pass = $option['pass'];
$name = $option['name'];
} else {
global $config;
$host = $config['db']['host'];
$user = $config['db']['user'];
$pass = $config['db']['pass'];
$name = $config['db']['name'];
}
$this->connection = new mysqli($host, $user, $pass, $name);
if ($this->connection->connect_error) {
echo "Connection failed: " . $this->connection->connect_error;
exit;
}
$this->connection->query("SET NAMES 'utf8'");
}
public function first($sql){
$records = $this->query($sql);
if ($records == null){
return null;
}
return $records[0];
}
public function insert($sql){
$id = $this->connection->query($sql);
return $id;
}
public function query($sql){
$result = $this->connection->query($sql);
$records = array();
if ($result->num_rows == 0) {
return null;
}
while($row = $result->fetch_assoc()) {
$records[] = $row;
}
return $records;
}
public function connection(){
return $this->connection;
}
public function close(){
$this->connection->close();
}
}
数据库已建立并填充了信息