Does UPDATE automatically checks to see if the data has changed before actually writing anything into the database (MySQL in question here)
For example, which is more efficient:
function update($a, $b, ..., $bar) {
mysql_query("UPDATE Foo SET A = '$a', B = '$b', ... WHERE Bar = $bar");
}
or
function update($a, $b, ...) {
mysql_query("SELECT A, B, ... WHERE Bar = $bar");
...
if(A different) {
mysql_query("UPDATE Foo SET A = '$a' WHERE Bar = $bar");
}
if(B different) {
mysql_query("UPDATE Foo SET B = '$b' WHERE Bar = $bar");
}
if(...) {
...
}
}
if most of the data in the row changes, then the first function should be more efficient, however, if only one field changes, is the second function more efficient?
For example, which is more efficient:
function update($a, $b, ..., $bar) {
mysql_query("UPDATE Foo SET A = '$a', B = '$b', ... WHERE Bar = $bar");
}
or
function update($a, $b, ...) {
mysql_query("SELECT A, B, ... WHERE Bar = $bar");
...
if(A different) {
mysql_query("UPDATE Foo SET A = '$a' WHERE Bar = $bar");
}
if(B different) {
mysql_query("UPDATE Foo SET B = '$b' WHERE Bar = $bar");
}
if(...) {
...
}
}
if most of the data in the row changes, then the first function should be more efficient, however, if only one field changes, is the second function more efficient?