{"id":541,"date":"2019-09-20T10:23:39","date_gmt":"2019-09-20T10:23:39","guid":{"rendered":"https:\/\/www.webhozz.com\/code\/?p=541"},"modified":"2019-09-20T10:23:41","modified_gmt":"2019-09-20T10:23:41","slug":"php-mysql-update","status":"publish","type":"post","link":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/","title":{"rendered":"PHP MySQL : Update"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">Update Database Tabel Data<\/h5>\n\n\n\n<p>Pernyataan UPDATE digunakan untuk mengubah atau memodifikasi\ncatatan yang ada di tabel database. Pernyataan ini biasanya digunakan bersama\ndengan klausa <strong><em>WHERE<\/em><\/strong> untuk menerapkan perubahan hanya pada catatan yang cocok\ndengan kriteria tertentu.<\/p>\n\n\n\n<p>Sintaks dasar pernyataan <strong><em>UPDATE<\/em><\/strong> dapat diberikan dengan:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img fetchpriority=\"high\" decoding=\"async\" width=\"781\" height=\"72\" src=\"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33.jpg\" alt=\"\" class=\"wp-image-542\" srcset=\"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33.jpg 781w, https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33-300x28.jpg 300w, https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33-768x71.jpg 768w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><\/figure>\n\n\n\n<p>Mari kita membuat query SQL menggunakan pernyataan <strong><em>UPDATE<\/em><\/strong> dan klausa <strong><em>WHERE<\/em><\/strong>, setelah itu kita akan mengeksekusi query ini dengan mengirimkannya ke fungsi PHP <strong><em>mysqli_query()<\/em><\/strong> untuk mengupdate catatan tabel. Pertimbangkan tabel <em>persons<\/em> berikut di dalam basis data <em>demo<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+----+------------+-----------+----------------------+\n| id | first_name | last_name | email                |\n+----+------------+-----------+----------------------+\n|  1 | Peter      | Parker    | peterparker@mail.com |\n|  2 | John       | Rambo     | johnrambo@mail.com   |\n|  3 | Clark      | Kent      | clarkkent@mail.com   |\n|  4 | John       | Carter    | johncarter@mail.com  |\n|  5 | Harry      | Potter    | harrypotter@mail.com |\n+----+------------+-----------+----------------------+<\/pre>\n\n\n\n<p>Kode PHP dalam contoh berikut ini akan memperbarui alamat email seseorang di tabel <em>persons<\/em> yang <strong><em>id<\/em><\/strong> nya sama dengan 1.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\/* Attempt MySQL server connection. Assuming you are running MySQL\nserver with default setting (user 'root' with no password) *\/\n$link = mysqli_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;, &quot;demo&quot;);\n \n\/\/ Check connection\nif($link === false){\n    die(&quot;ERROR: Could not connect. &quot; . mysqli_connect_error());\n}\n \n\/\/ Attempt update query execution\n$sql = &quot;UPDATE persons SET email='peterparker_new@mail.com' WHERE id=1&quot;;\nif(mysqli_query($link, $sql)){\n    echo &quot;Records were updated successfully.&quot;;\n} else {\n    echo &quot;ERROR: Could not able to execute $sql. &quot; . mysqli_error($link);\n}\n \n\/\/ Close connection\nmysqli_close($link);\n?&gt;\n<\/pre><\/div>\n\n\n<p>Setelah memperbarui tabel <em>persons<\/em> maka akan terlihat seperti ini:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+----+------------+-----------+--------------------------+\n| id | first_name | last_name | email                    |\n+----+------------+-----------+--------------------------+\n|  1 | Peter      | Parker    | peterparker_new@mail.com |\n|  2 | John       | Rambo     | johnrambo@mail.com       |\n|  3 | Clark      | Kent      | clarkkent@mail.com       |\n|  4 | John       | Carter    | johncarter@mail.com      |\n|  5 | Harry      | Potter    | harrypotter@mail.com     |\n+----+------------+-----------+--------------------------+<\/pre>\n\n\n\n<p><strong><em>Peringatan:<\/em><\/strong> Klausa <strong><em>WHERE<\/em><\/strong> dalam pernyataan <strong><em>UPDATE<\/em><\/strong> akan menentukan catatan atau catatan mana yang harus diperbarui. Jika kalian menghilangkan klausa <strong><em>WHERE<\/em><\/strong>, maka semua catatan akan otomatis diperbarui.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update Database Tabel Data Pernyataan UPDATE digunakan untuk mengubah atau memodifikasi catatan yang ada di tabel database. Pernyataan ini biasanya digunakan bersama dengan klausa WHERE<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-541","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Belajar PHP MySQL : Update - WebHozz Code<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhozz.com\/code\/php-mysql-update\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Belajar PHP MySQL : Update - WebHozz Code\" \/>\n<meta property=\"og:description\" content=\"Update Database Tabel Data Pernyataan UPDATE digunakan untuk mengubah atau memodifikasi catatan yang ada di tabel database. Pernyataan ini biasanya digunakan bersama dengan klausa WHERE\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhozz.com\/code\/php-mysql-update\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHozz Code\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-20T10:23:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-20T10:23:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"781\" \/>\n\t<meta property=\"og:image:height\" content=\"72\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\"},\"headline\":\"PHP MySQL : Update\",\"datePublished\":\"2019-09-20T10:23:39+00:00\",\"dateModified\":\"2019-09-20T10:23:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/\"},\"wordCount\":138,\"image\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/Untitled-1-33.jpg\",\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/\",\"name\":\"Belajar PHP MySQL : Update - WebHozz Code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/Untitled-1-33.jpg\",\"datePublished\":\"2019-09-20T10:23:39+00:00\",\"dateModified\":\"2019-09-20T10:23:41+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/Untitled-1-33.jpg\",\"contentUrl\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/Untitled-1-33.jpg\",\"width\":781,\"height\":72},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-mysql-update\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP MySQL : Update\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\",\"name\":\"WebHozz Code\",\"description\":\"Tutorial Web &amp; Pemrograman Indonesia\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/author\\\/dody\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Belajar PHP MySQL : Update - WebHozz Code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/","og_locale":"en_US","og_type":"article","og_title":"Belajar PHP MySQL : Update - WebHozz Code","og_description":"Update Database Tabel Data Pernyataan UPDATE digunakan untuk mengubah atau memodifikasi catatan yang ada di tabel database. Pernyataan ini biasanya digunakan bersama dengan klausa WHERE","og_url":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/","og_site_name":"WebHozz Code","article_published_time":"2019-09-20T10:23:39+00:00","article_modified_time":"2019-09-20T10:23:41+00:00","og_image":[{"width":781,"height":72,"url":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/#article","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/"},"author":{"name":"admin","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1"},"headline":"PHP MySQL : Update","datePublished":"2019-09-20T10:23:39+00:00","dateModified":"2019-09-20T10:23:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/"},"wordCount":138,"image":{"@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33.jpg","articleSection":["PHP"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/","url":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/","name":"Belajar PHP MySQL : Update - WebHozz Code","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/#primaryimage"},"image":{"@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33.jpg","datePublished":"2019-09-20T10:23:39+00:00","dateModified":"2019-09-20T10:23:41+00:00","author":{"@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1"},"breadcrumb":{"@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhozz.com\/code\/php-mysql-update\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/#primaryimage","url":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33.jpg","contentUrl":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2019\/09\/Untitled-1-33.jpg","width":781,"height":72},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhozz.com\/code\/php-mysql-update\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhozz.com\/code\/"},{"@type":"ListItem","position":2,"name":"PHP MySQL : Update"}]},{"@type":"WebSite","@id":"https:\/\/www.webhozz.com\/code\/#website","url":"https:\/\/www.webhozz.com\/code\/","name":"WebHozz Code","description":"Tutorial Web &amp; Pemrograman Indonesia","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhozz.com\/code\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.webhozz.com\/code\/author\/dody\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/comments?post=541"}],"version-history":[{"count":1,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/541\/revisions"}],"predecessor-version":[{"id":543,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/541\/revisions\/543"}],"wp:attachment":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/media?parent=541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/categories?post=541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/tags?post=541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}