fetching DB entries
| From: | Ashley Sheridan | Date: | Mon, 21 Jun 2010 18:31:39 +0000 |
| Subject: | fetching DB entries | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-306299@lists.php.net to get a copy of this message | ||
Hi All,
This is just a bit of a 'throw it out to the masses' sort of question to
see what people might recommend.
At the moment, if I am retrieving a single record from the DB, my code
looks like this:
$query = "SELECT * FROM table WHERE id=1";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
return $row;
}
Now, aside from the actual SQL involved, is this efficient? Would it
gain me anything if I used mysql_result() statements instead, or would
that only be efficient if there were a small number of fields I was
retrieving data for? Should I use something else entirely?
I've not got to the testing this myself, as I figured something like
this might be common knowledge for all of you who are better than me at
optimisation.
Is it even an issue if I'm only retrieving a single record in this
manner (I always make my id field in a table the primary key, so it
means I won't ever be retrieving more than one record)
Thanks in advance for any input you guys have!
Thanks,
Ash
http://www.ashleysheridan.co.uk