SQL optimized MySQL PHP
Prawn, please help me optimize this SQL statement
$sql = "UPDATE". $table. " ' SET $field = concat (' ". $value [' result ']." {HX} ', now (), ' {HX} '. $value [' name ']. " {HX} '. $value [' op ']. " {HX} '. $value [' suggestion ']. "') $auditing WHERE ' id ' = '. $value [' id '];
Global $conn;
mysql_query ($sql, $conn);
if ($auditing = = ", ' check ' = ' yes ') {
$sql = "Select ' mu_id ' from ' $table ' WHERE ' id ' = $value [id] LIMIT 1";
$sql = mysql_query ($sql, $conn);
$mu _id = mysql_fetch_array ($sql);
$sql = "UPDATE ' member_user ' SET ' check ' = ' yes ', ' UpdateTime ' =now () WHERE ' id ' = $mu _id[0]";
mysql_query ($sql, $conn);
}
Unset ($conn);
Return "approval success";
Reply to discussion (solution)
Put Concat (' ". $value [' result ']." {HX} ', now (), ' {HX} '. $value [' name ']. " {HX} '. $value [' op ']. " {HX} '. $value [' suggestion ']. "') This is implemented in PHP, not with SQL Concat.
There is the database index, which is very helpful to improve the speed
Is there anything else you can do to optimize the next few words?
if ($auditing = = ", ' check ' = ' yes ') {$sql =" select ' mu_id ' from ' $table ' WHERE ' id ' = $value [id] LIMIT 1 "; $sql = mysql_query ($sql, $conn); $mu _id = Mysql_fetch_array ($sql); $sql = "UPDATE ' member_user ' SET ' check ' = ' yes ', ' UpdateTime ' =now () WHERE ' ID ' = $mu _id[0] "; mysql_query ($sql, $conn);} Can be changed to if ($auditing = = ", ' check ' = ' yes ') {$sql = ' UPDATE ' member_user ' SET ' check ' = ' yes ', ' UpdateTime ' =now () WHERE ' id ' in (SE Lect ' mu_id ' from ' $table ' WHERE ' id ' = $value [id] LIMIT 1) "; mysql_query ($sql, $conn);//The statement is simplified, but if the index is good, it should be promoted. , mostly indexed for member_user.id,mu_id,id fields}
Thanks, Baoxiaohua. Simplifies SQL statements