我的PHP脚本中仍然有mysql错误。
有问题的代码:
$mquery = mysql_query("SELECT m.`id`, m.`name`, NULL AS `type`, NULL AS `code`, 0 AS `cat` FROM `menu` m UNION ALL SELECT l.`id`, l.`name`, l.`type`, l.`code`, l.`cat` FROM `lines` l UNION ALL SELECT s.`id`, s.`name`, s.`site`, s.`site`, s.`cat` FROM `sites` s ORDER BY `name` ASC");
if(!$mquery) { echo mysql_error(); die(); }
while($mdata = mysql_fetch_assoc($mquery)) { ... }当我把这个查询放到PhpMyAdmin中时--一切正常,我就会得到结果。当我将这个查询放入MySQL工作台时--一切正常,我将得到结果。
现在:当我使用参数(http://domain/index.php?site=ABC)运行脚本时,一切正常。当我运行没有参数的脚本(http://domain/index.php)时,我会得到这个查询的mysql错误:“表'test.menu‘不存在”。
什么“test.menu”!“测试”在哪里?我不想要任何“测试”,我的查询中没有“测试”。为什么它与url中的参数有关?它不是动态生成的查询。问题在哪里?
对不起我的英语
已解决,脚本结构:
$mydb = mysql_connect(...);
mysql_select_db(..., $mydb);
mysql_set_charset('utf8', $mydb);
function newMenu($db)
{
$mquery = mysql_query("...", $db);
if(!$mquery) { echo mysql_error(); die(); }
while($mdata = mysql_fetch_assoc($mquery) { ... }
}
myMenu($mydb);但我不明白的是:当参数'site‘在url中时,它为什么没有"$db“而工作呢?
发布于 2017-07-17 09:08:04
请检查PHP中的mysql配置。我很确定您正在使用数据库名作为“测试”,因为您已经从某个地方复制了代码。将其更改为数据库的实际名称,它将工作。
mysql_query的第二个参数必须是一个连接变量。
<?php
$con = mysql_connect("localhost", "root", "mypass") or
die("Could not connect: " . mysql_error());
mysql_select_db("tutorials");
$result = mysql_query("select * from tutorials");
echo "<h2>Here is a list of the topics:</h2>";
while ($row = mysql_fetch_array($result)) {
echo $row['name']."<br />";
}
mysql_close($con);
?> 发布于 2017-07-17 09:15:47
你能给出完整的php脚本吗?数据库配置是否与“站点”参数相关?
https://stackoverflow.com/questions/45139991
复制相似问题