1 / 8

Pemrograman Web

Pemrograman Web. Database Create-Retrieve-Update-Delete (CRUD). Definisi Tabel. Database Name: test Table Name: bukutamu CREATE TABLE IF NOT EXISTS `bukutamu` ( `id` int(11) NOT NULL AUTO_INCREMENT, `nama` varchar(50) NOT NULL, `email` varchar(50) NOT NULL,

mercia
Download Presentation

Pemrograman Web

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pemrograman Web Database Create-Retrieve-Update-Delete (CRUD)

  2. DefinisiTabel • Database Name: test • Table Name: bukutamu CREATE TABLE IF NOT EXISTS `bukutamu` ( `id` int(11) NOT NULL AUTO_INCREMENT, `nama` varchar(50) NOT NULL, `email` varchar(50) NOT NULL, `pesan` mediumtext NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

  3. Eksekusi MySQL Query Generik via PHP $host = '127.0.0.1'; // localhost $db = 'test'; $user = 'root'; $pass = ""; // the password is an empty string if($con = mysql_connect($host, $user, $pass)) { mysql_select_db($db, $con); $sql = "..."; // put your query here... $result = mysql_query( $sql ); }

  4. Create • Memasukkan data/informasimelaluisebuah form kedalamtabel di dalam database MySQL • DML INSERT $sql = "INSERT INTO bukutamu (nama, email, pesan) VALUES( '$nama', '$email', '$pesan' ); // $nama, $email, dan $pesan // diperolehdari $_POST atau $_GET

  5. Retreive / Read • Mengambil data/informasidaridalamtabel di dalam database MySQL • DML SELECT $sql = "SELECT nama, email, pesan FROM bukutamu;" • Fetch array dari query result: while( $row = mysql_fetch_array ( $result ) ) { echo "<p>" . $row['nama'] . " – "; echo "$row['email'] . " – "; echo "$row['pesan'] . "<p>"; }

  6. Update • Memperbarui data/informasipadatabel di dalam database MySQL • DML UPDATE $sql = "UPDATE bukutamu SET nama = '$nama', email = '$email', pesan = '$pesan' WHERE id = '$id';" // $nama, $email, $pesan, dan $id // diperolehdari $_POST atau $_GET // $id adalah PRIMARY KEY padatabelbukutamu

  7. Delete • Menghapus data/informasi/barispadatabeldi dalam database MySQL • DML DELETE $sql = "DELETE FROM bukutamu WHERE id = '$id';" // $id diperolehdari $_POST atau $_GET // $id adalah PRIMARY KEY padatabelbukutamu

  8. PHP-MySQL Administration Helper Tools • GunakanphpMyAdmin (PMA) • Penggunaan • Download dari:http://www.phpmyadmin.net/home_page/index.php • Extract zip/.tar.gz file yang di-download di root directory webserver (umumnyadalam folder htdocs/) • Copy/rename file config.sample.inc.phpphpMyAdminmenjadiconfig.inc.php • Buka file config.inc.php, ubahkonfigurasiyangdibutuhkan, dan save. • Aksesdari http://localhost/phpMyAdmin-[versi]-[lang]

More Related