can I use mysql_fetch_array(mysql_query('...'))?
or is that the only way:
$res = mysql_query($sql);
$data = array();
while(($row = mysql_fetch_array($res)) !== false) {
$data[] = $row;
}
NOTE that I’m expecting only ONE row/result
You can, yes (if you expect only one row returned), but you probably shouldn’t.
It is important to check the success or failure of
mysql_query()before attempting to fetch a result from it. Ifmysql_query()fails, it will passFALSEtomysql_fetch_array(), and that will result it in an error likeIt is much safer to assign the output of
mysql_query()to a variable which is a result resource, and test its success or failure.In any case you cannot do
mysql_fetch_array(mysql_query(...))if you expect more than one result returned.