Shazer2 Posted December 15, 2011 Share Posted December 15, 2011 I am receiving this error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/shannon/public_html/booter/inc/classes/class.db.php on line 17 For the function: function fetch_array($query) { $array = mysql_fetch_assoc($query); return $array; } Why would I receive that error, if I am just passing a variable? Not a resource or boolean? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/ Share on other sites More sharing options...
SergeiSS Posted December 15, 2011 Share Posted December 15, 2011 This warning mean that you have an error in you MySQL request. Show it. Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298053 Share on other sites More sharing options...
Shazer2 Posted December 15, 2011 Author Share Posted December 15, 2011 Well I'm calling it like this: $query = $db->select("boot", "id, uid", "id=1"); while ($rows = $db->fetch_array($query)) { echo $rows['id']." - ".$rows['uid']; } Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298055 Share on other sites More sharing options...
SergeiSS Posted December 15, 2011 Share Posted December 15, 2011 $query = $db->select("boot", "id, uid", "id=1"); It's a very great line! But why are you sure that all people knows the internal part of this function, it's parameters and so on? It's not a request, it's a call to the function that could do it and send to MySQL - I don't know, I can suggest it only. Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298059 Share on other sites More sharing options...
Shazer2 Posted December 15, 2011 Author Share Posted December 15, 2011 Sorry, this is the function. function select($table, $rows = "*", $cond = "") { $query = "SELECT {$rows} FROM `{$table}`"; if ($cond != "") { $query .= " WHERE {$cond}"; } return mysql_query($query); } Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298062 Share on other sites More sharing options...
SergeiSS Posted December 15, 2011 Share Posted December 15, 2011 OK... You might have a query SELECT id,uid FROM `boot` WHERE id=1 Did you try to execute it from phpmyadmin? It seems that something is wrong it this query. Function mysql_error() could be useful for you to see exactly what is wrong. You may try to use it just after you make a call to function select(). Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298066 Share on other sites More sharing options...
Shazer2 Posted December 15, 2011 Author Share Posted December 15, 2011 I just realised a few things, firstly I wasn't selecting a database and secondly I had the wrong table name. I corrected both but I'm still getting this error. Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/shannon/public_html/booter/inc/classes/class.db.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298067 Share on other sites More sharing options...
SergeiSS Posted December 15, 2011 Share Posted December 15, 2011 The only (real) way to solve this kind of problems is to see the text of query. // Insert this code echo $query.'<br>'; //before this return mysql_query($query); And then show this query here. Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298081 Share on other sites More sharing options...
Shazer2 Posted December 15, 2011 Author Share Posted December 15, 2011 I figured it out, I guess I wasn't connecting OR selecting a database as in the construct for my DB class I was doing. function __construct() { return self::connect(); return self::select_db(); } Instead of function __construct() { self::connect(); self::select_db(); } I changed it to the second code, and now everything works fine. Thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298090 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.