Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top