MySQL error: mysql
Possible Duplicate:
Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given error
I recently got a work from a client, where I have to change the depreciated php old code to new one. In that code I came across mysql_db_query which I converted into mysql_query but the error was given
mysql_fetch_array expects parameter 1 to be resource, boolean given
//the old code was like:
$result = mysql_db_query($mysql_db,"SELECT Hierarchy FROM MenuSystem WHERE LENGTH(Hierarchy) >= 2 AND LOCATE(" . $_SESSION['AccessLevel'] . ",AccessLevels) <> 0;");
//and my new code is :
$result = mysql_query("SELECT Hierarchy FROM MenuSystem WHERE LENGTH(Hierarchy) >= 2 AND LOCATE(" . $_SESSION['AccessLevel'] . ",AccessLevels) <> 0");
please tell me the problem
it refers to line number 11 where is the end bracket of while loop
while ($row = mysql_fetch_array($result)) {
$ConcatHierarchy .= $row["Hierarchy"];
}
I can't see that the sole code will cause error. However, if you want to use $result as an array, that may rise a problem as we need to check it first. If query fails it will return a FALSE rather than a resource ie, an array.
(I mean you use the resource later as an array actually. But yes $result is either a FALSE or a resrouce which can be used by calling mysql_fetch_array(). thanks for your comment)
Actually you can check other posts such as: mysql_fetch_array() expects parameter 1 to be resource problem
fyi, as suggested by the manual, ppl may prefer PDO now: Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used.
You're doing a string operating, on something that's lacking quotes to make it into a string:
... AND LOCATE(" . $_SESSION['AccessLevel'] . ",AccessLevels) <> 0");
^-- ^---
the indicated points require single quotes ( '
). Right now you're probably embedding some string, like 'SuperUser' in there. Without the quotes, that appears to MySQL as a field name, which almost certainly doesn't exist.
if you'd had appropriate error handling in your code, you'd have seen this immediately from the error message:
$result = mysql_query(...) or die(mysql_error());
^^^^^^^^^^^^^^^^^^^^^^--- bare minimum
链接地址: http://www.djcxy.com/p/69414.html
上一篇: PHP解析错误:语法错误,意外的T
下一篇: MySQL错误:mysql