我试图解决这个问题,在查看了这个问题的所有其他副本之后,我的问题仍然没有得到解答。
我是PHP的初学者,但我很确定我的代码很好......但显然不是。
请帮忙吗?
我的代码如下......
// Get some site-wide variables from the database first
$settings = mysql_query("SELECT * FROM cms_settings");
// Put the site settings into usable variables
while($row = mysql_fetch_array($settings)) {
$site_name = $row['name'];
$site_desc = $row['description'];
$site_status = $row['status'];
}
答案 0 :(得分:4)
您的查询失败,这意味着变量$ settings是一个布尔值FALSE值。试试这个:
$settings = mysql_query("SELECT * FROM cms_settings");
if($settings === false){
throw new Exception(mysql_error());
}
根据您上面的评论判断,在尝试运行查询之前,您没有选择数据库。尝试:
mysql_select_db('your_database_name');
$settings = mysql_query("SELECT * FROM cms_settings");
if($settings === false){
throw new Exception(mysql_error());
}