Jump to content

mysql_fetch_assoc()


Shazer2

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/
Share on other sites

$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.

Link to comment
https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298059
Share on other sites

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().

Link to comment
https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298066
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298067
Share on other sites

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!

 

Link to comment
https://forums.phpfreaks.com/topic/253202-mysql_fetch_assoc/#findComment-1298090
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.