Mysql
 sql >> Database >  >> RDS >> Mysql

avviso php mysql_fetch_assoc

In genere, le funzioni mysql_* vengono utilizzate come segue:

$id = 1234;
$query = 'SELECT name, genre FROM sometable WHERE id=' . $id;
// $query is a string with the MySQL query
$resource = mysql_query($query);
// $resource is a *MySQL result resource* - a mere link to the result set
while ($row = mysql_fetch_assoc($resource)) { 
    // $row is an associative array from the result set
    print_r($row);
    // do something with $row
}

Se si passa qualcosa a mysql_fetch_assoc che non è una risorsa di risultato MySQL (che sia una stringa, un oggetto o un booleano), la funzione si lamenterà di non sapere cosa fare con il parametro; che è esattamente quello che stai vedendo.

Un trucco comune :ricevi questo avviso se passi qualcosa (diverso da una stringa di query valida) a mysql_query :

$id = null;
$query = 'SELECT name, genre FROM sometable WHERE id=' . $id;
$res = mysql_query($query); 
// $res === FALSE because the query was invalid
// ( "SELECT name, genre FROM sometable WHERE id=" is not a valid query )
mysql_fetch_assoc($res); 
// Warning: don't know what to do with FALSE, as it's not a MySQL result resource