views:

48

answers:

1

Is there a faster way to perform this most simple query in terms of server load? I don't think I've ever tried anything other than this method:

$sql = 'SELECT thing FROM table WHERE id="' . $id . '" ';
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
$thing = $row[0];

Any way to improve this?

+5  A: 

Performance wise you can create an index on id if not already done.

Security wise you are open to SQL-injection attack, use prepares statements instead.

codaddict