这是 config.php 文件
<?php
error_reporting(E_ALL ^ E_NOTICE);
/*=========== Database Configuraiton ==========*/
$db_host = "localhost";
$db_user = "test";
$db_pass = "test";
$db_name = "dbtest";
/*=========== Website Configuration ==========*/
$defaultTitle = 'testing';
$defaultFooter = date('Y').' © testing';
?>
这是对 config.php 的引用
<?php
require_once "includes/config.php";
require_once "includes/connect.php";
require_once "includes/helpers.php";
header('Cache-Control: max-age=3600, public');
header('Pragma: cache');
header("Last-Modified: ".gmdate("D, d M Y H:i:s",time())." GMT");
header("Expires: ".gmdate("D, d M Y H:i:s",time()+3600)." GMT");
?>
Connect.php 在下面
<?php
/*
The login details are taken from config.php.
*/
try {
$db = new PDO(
"mysql:host=$db_host;dbname=$db_name;charset=UTF-8",
$db_user,
$db_pass
);
$db->query("SET NAMES 'utf8'");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
error_log($e->getMessage());
die("A database error was encountered");
}
?>
有人看到这段代码的问题吗?我从 connect.php 收到错误消息“遇到数据库错误”我需要另一双眼睛,因为我的所有信息看起来都是正确的,而且我在代码中看不到错误。谢谢。