Object Oriented Style
$stmt = $maindb->prepare("UPDATE some_table SET
MyStringColumn = ?,
MyIntColumn = ?
WHERE MyColumn = ?
");
$stmt->bind_param("sii", $MyStringColumn, $MyIntColumn, $MyRowId);
$stmt->execute();
$stmt->close();
How many rows were affected
$stmt->execute();
$NumOfAffectedRows = $stmt->affected_rows;
$stmt->close();
Procedural Style
$result = mysqli_query($dblink, "UPDATE some_table SET
image_filename = '',
something_else = 4
WHERE indexer = $destid
");
if ( ($result != TRUE) || (mysqli_affected_rows($dblink) < 1) )
die("ERROR - Couldn't update");
Maths Operations In Update Queries
mysqli_query($dblink, "UPDATE some_table SET some_value_a = some_value_a + 1, some_value_b = some_value_b + 10 WHERE id = 1");
Add text to an existing text field
UPDATE MyTable SET MyFieldName = CONCAT_WS('', MyFieldName, ' [UserBlocked ]') WHERE user_id = %d"
UPDATE MyTable SET MyFieldName = CONCAT_WS('', MyFieldName, ' [UserBlocked ', Now(), ' Reason: %d]') WHERE user_id = %d"
//N.B. CONCAT_WS allows this to work if the field is currently null (CONCAT will fail) and the first '', is required
//as it is what CONCAT_WS inserts between each of the following string fields (nothing in this case)
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.