I've got a mysql statement which grabs only one record according to an id. I wish to determine if using mysql_fetch_row or something like that like that's better then using similar to mysql_fetch_array, just for getting one row inside a database.
It might appear like good sense to choose the mysql_fetch_row but Among the finest to make certain.
An essential factor to notice is the fact that using
mysql_fetch_array()is not considerably reduced than using
mysql_fetch_row(), while it possesses a significant added value.
why not only use
LIMIT 1 within the mysql statement and regardless of what you'll have one row.
The 2 functions are almost identical, the title is simply causing you to think it's different:
$r=mysql_query('SELECT name,email FROM tbl LIMIT 1'); var_dump(mysql_fetch_assoc($r)); // array('name'=>[dbName], 'email'=>[dbEmail]); var_dump(mysql_fetch_row($r)); // array([dbName], [dbEmail]); // It's a normal incremental integer index array var_dump(mysql_fetch_array($r,MYSQL_ASSOC)); // same as mysql_fetch_assoc(); var_dump(mysql_fetch_array($r,MYSQL_NUM)); // same as mysql_fetch_row(); var_dump(mysql_fetch_array($r,MYSQL_BOTH)); // array(0=>[dbName], 1=>[dbEmail], 'name'=>[dbName], 'email'=>[dbEmail]);
The manual also indicates performance smart the 2 functions worked out well. Local tests hint within the same direction. I'd suggest explore be worried about the .0001 time/memory saved and discover true bottlenecks inside your programs.