{"id":449,"date":"2012-07-19T12:43:49","date_gmt":"2012-07-19T12:43:49","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=449"},"modified":"2022-02-17T07:14:04","modified_gmt":"2022-02-17T07:14:04","slug":"update","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/queries\/update-queries\/update","title":{"rendered":".UPDATE general"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Object Oriented Style<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $stmt = $maindb->prepare(\"UPDATE some_table SET\n        MyStringColumn = ?,\n        MyIntColumn = ?\n      WHERE MyColumn = ?\n    \");\n  $stmt->bind_param(\"sii\", $MyStringColumn, $MyIntColumn, $MyRowId);\n  $stmt->execute();\n  $stmt->close();<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">How many rows were affected<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $stmt->execute();\n  $NumOfAffectedRows = $stmt->affected_rows;\n  $stmt->close();<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Procedural&nbsp;Style<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\t$result = mysqli_query($dblink, \"UPDATE some_table SET\n\t\t\t\t\t\timage_filename = '',\n\t\t\t\t\t\tsomething_else = 4\n\t\t\t\t\tWHERE indexer = $destid\n\t\t\t\t\t\");\n\tif ( ($result != TRUE) || (mysqli_affected_rows($dblink) &lt; 1) )\n\t\tdie(\"ERROR - Couldn't update\");<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Maths Operations In Update Queries<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\tmysqli_query($dblink, \"UPDATE some_table SET some_value_a = some_value_a + 1, some_value_b = some_value_b + 10  WHERE id = 1\");<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Add text to an existing text field<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  UPDATE MyTable SET MyFieldName = CONCAT_WS('', MyFieldName, ' &#91;UserBlocked ]') WHERE user_id = %d\"\n\n  UPDATE MyTable SET MyFieldName = CONCAT_WS('', MyFieldName, ' &#91;UserBlocked ', Now(), ' Reason: %d]') WHERE user_id = %d\"\n\n  \/\/N.B. CONCAT_WS allows this to work if the field is currently null (CONCAT will fail) and the first '', is required\n  \/\/as it is what CONCAT_WS inserts between each of the following string fields (nothing in this case)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Object Oriented Style How many rows were affected Procedural&nbsp;Style Maths Operations In Update Queries Add text to an existing text field<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[240],"tags":[],"class_list":["post-449","post","type-post","status-publish","format-standard","hentry","category-update-queries"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":27,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":3092,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/449\/revisions\/3092"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}