{"id":505,"date":"2019-09-16T12:00:55","date_gmt":"2019-09-16T12:00:55","guid":{"rendered":"https:\/\/www.webhozz.com\/code\/?p=505"},"modified":"2019-09-16T12:25:32","modified_gmt":"2019-09-16T12:25:32","slug":"php-membuat-tabel-mysql","status":"publish","type":"post","link":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/","title":{"rendered":"PHP MySQL : Membuat Tabel MySQL"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">Membuat Tabel di dalam Database MySQL Menggunakan PHP <\/h5>\n\n\n\n<p>Pada bab sebelumnya kita telah belajar cara membuat database\ndi server MySQL. Sekarang saatnya membuat beberapa tabel di dalam database yang\nbenar-benar akan menyimpan data. Sebuah tabel mengatur informasi menjadi baris\ndan kolom.<\/p>\n\n\n\n<p>Pernyataan SQL CREATE TABLE digunakan untuk membuat tabel\ndalam database.<\/p>\n\n\n\n<p>Mari kita membuat query SQL menggunakan pernyataan <strong><em>CREATE TABLE<\/em><\/strong>, setelah itu kita akan mengeksekusi query SQL ini dengan mengirimkannya ke fungsi PHP <strong><em>mysqli_query()<\/em><\/strong> untuk akhirnya membuat tabel kita.<\/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 create table query execution\n$sql = &quot;CREATE TABLE persons(\n    id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,\n    first_name VARCHAR(30) NOT NULL,\n    last_name VARCHAR(30) NOT NULL,\n    email VARCHAR(70) NOT NULL UNIQUE\n)&quot;;\nif(mysqli_query($link, $sql)){\n    echo &quot;Table created 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>Kode PHP dalam contoh di atas membuat tabel bernama <em>persons<\/em> dengan empat kolom id, <em>first_name<\/em>, <em>last_name<\/em> dan <em>email<\/em> di\ndalam database <em>demo<\/em>.<\/p>\n\n\n\n<p>Perhatikan bahwa setiap nama bidang diikuti oleh deklarasi\ntipe data; deklarasi ini menentukan jenis data apa yang bisa dimiliki oleh\nkolom, apakah bilangan bulat, string, tanggal, dll.<\/p>\n\n\n\n<p>Ada beberapa kendala tambahan (juga disebut pengubah) yang ditentukan setelah nama kolom dalam pernyataan SQL sebelumnya, seperti <strong><em>NOT NULL<\/em><\/strong>, <strong><em>PRIMARY KEY<\/em><\/strong>, <strong><em>AUTO_INCREMENT<\/em><\/strong>, dll. Kendala menentukan aturan mengenai nilai yang diizinkan dalam kolom.<\/p>\n\n\n\n<p><strong><em>Catatan: <\/em><\/strong>Sejumlah jeda baris dapat terjadi dalam pernyataan SQL, asalkan setiap jeda baris tidak memutuskan kata kunci, nilai, expression, dll.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Membuat Tabel di dalam Database MySQL Menggunakan PHP Pada bab sebelumnya kita telah belajar cara membuat database di server MySQL. Sekarang saatnya membuat beberapa tabel<\/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-505","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Belajar PHP MySQL : Membuat Tabel MySQL - 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-membuat-tabel-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Belajar PHP MySQL : Membuat Tabel MySQL - WebHozz Code\" \/>\n<meta property=\"og:description\" content=\"Membuat Tabel di dalam Database MySQL Menggunakan PHP Pada bab sebelumnya kita telah belajar cara membuat database di server MySQL. Sekarang saatnya membuat beberapa tabel\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHozz Code\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-16T12:00:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-16T12:25:32+00:00\" \/>\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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-membuat-tabel-mysql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-membuat-tabel-mysql\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\"},\"headline\":\"PHP MySQL : Membuat Tabel MySQL\",\"datePublished\":\"2019-09-16T12:00:55+00:00\",\"dateModified\":\"2019-09-16T12:25:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-membuat-tabel-mysql\\\/\"},\"wordCount\":189,\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-membuat-tabel-mysql\\\/\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-membuat-tabel-mysql\\\/\",\"name\":\"Belajar PHP MySQL : Membuat Tabel MySQL - WebHozz Code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\"},\"datePublished\":\"2019-09-16T12:00:55+00:00\",\"dateModified\":\"2019-09-16T12:25:32+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-membuat-tabel-mysql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-membuat-tabel-mysql\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-membuat-tabel-mysql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP MySQL : Membuat Tabel MySQL\"}]},{\"@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 : Membuat Tabel MySQL - 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-membuat-tabel-mysql\/","og_locale":"en_US","og_type":"article","og_title":"Belajar PHP MySQL : Membuat Tabel MySQL - WebHozz Code","og_description":"Membuat Tabel di dalam Database MySQL Menggunakan PHP Pada bab sebelumnya kita telah belajar cara membuat database di server MySQL. Sekarang saatnya membuat beberapa tabel","og_url":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/","og_site_name":"WebHozz Code","article_published_time":"2019-09-16T12:00:55+00:00","article_modified_time":"2019-09-16T12:25:32+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/#article","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/"},"author":{"name":"admin","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1"},"headline":"PHP MySQL : Membuat Tabel MySQL","datePublished":"2019-09-16T12:00:55+00:00","dateModified":"2019-09-16T12:25:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/"},"wordCount":189,"articleSection":["PHP"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/","url":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/","name":"Belajar PHP MySQL : Membuat Tabel MySQL - WebHozz Code","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/#website"},"datePublished":"2019-09-16T12:00:55+00:00","dateModified":"2019-09-16T12:25:32+00:00","author":{"@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1"},"breadcrumb":{"@id":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhozz.com\/code\/php-membuat-tabel-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhozz.com\/code\/"},{"@type":"ListItem","position":2,"name":"PHP MySQL : Membuat Tabel MySQL"}]},{"@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\/505","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=505"}],"version-history":[{"count":2,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/505\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/505\/revisions\/511"}],"wp:attachment":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/media?parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/categories?post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/tags?post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}