Download PW-04 Database CRUD

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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,
`pesan` mediumtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Eksekusi MySQL Query Generik via PHP
$host
$db =
$user
$pass
= '127.0.0.1'; // localhost
'test';
= 'root';
= ""; // 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 );
}
Create


Memasukkan data/informasi melalui sebuah form ke
dalam tabel di dalam database MySQL
DML INSERT
$sql = "INSERT INTO bukutamu (nama, email, pesan)
VALUES( '$nama', '$email', '$pesan' );
// $nama, $email, dan $pesan
// diperoleh dari $_POST atau $_GET
Retreive / Read


Mengambil data/informasi dari dalam tabel di dalam
database MySQL
DML SELECT
$sql = "SELECT nama, email, pesan
FROM bukutamu;"

Fetch array dari query result:
while(
echo
echo
echo
}
$row = mysql_fetch_array ( $result ) ) {
"<p>" . $row['nama'] . " – ";
"$row['email'] . " – ";
"$row['pesan'] . "<p>";
Update


Memperbarui data/informasi pada tabel di dalam
database MySQL
DML UPDATE
$sql = "UPDATE bukutamu
SET nama = '$nama', email = '$email',
pesan = '$pesan' WHERE id = '$id';"
// $nama, $email, $pesan, dan $id
// diperoleh dari $_POST atau $_GET
// $id adalah PRIMARY KEY pada tabel bukutamu
Delete


Menghapus data/informasi/baris pada tabel di
dalam database MySQL
DML DELETE
$sql = "DELETE FROM bukutamu
WHERE id = '$id';"
// $id diperoleh dari $_POST atau $_GET
// $id adalah PRIMARY KEY pada tabel bukutamu
PHP-MySQL Administration Helper Tools


Gunakan phpMyAdmin (PMA)
Penggunaan





Download dari:
http://www.phpmyadmin.net/home_page/index.php
Extract zip/.tar.gz file yang di-download di root directory
webserver (umumnya dalam folder htdocs/)
Copy/rename file config.sample.inc.php phpMyAdmin
menjadi config.inc.php
Buka file config.inc.php, ubah konfigurasi yang
dibutuhkan, dan save.
Akses dari http://localhost/phpMyAdmin-[versi]-[lang]