简体   繁体   中英

Is there a faster way to perform this mysql query?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM