• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Wek14 mysql 2
 

Wek14 mysql 2

on

  • 1,198 views

 

Statistics

Views

Total Views
1,198
Views on SlideShare
1,198
Embed Views
0

Actions

Likes
0
Downloads
65
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Wek14 mysql 2 Wek14 mysql 2 Presentation Transcript

    • By I Wayan Simpen Pemrograman Web II With MySql (Kont.)
    • Fungsi-fungsi MySql
      • Fungsi mysql_connect
      • Bentuk:
      Membuat hubungan ke database MySQL yang terdapat pada suatu host. mysql_connect ( host, nama_user, password )
    • Fungsi-fungsi MySql (Kont.)
      • Contoh:
      <?php $nama_server = &quot;localhost&quot;; $nama_user = &quot;root&quot;; $password = &quot;&quot;; $database = &quot;Perpus&quot;; $id_mysql= mysql_connect ($nama_server,$nama_user,$password); if(! $id_mysql) die(&quot;Database MySQL tak dapat dibuka&quot;); if (! mysql_select_db($database,$id_mysql)) die(&quot;Database tak dalat dipilih&quot;); ?>
    • Fungsi-fungsi MySql (Kont.)
      • Fungsi mysql_query
      • Bentuk:
      Mengeksekusi permintaan (query) terhadap sebuah table atau sejumlah table. mysql_query ( permintaan, pengenal_hubungan )
    • Fungsi-fungsi MySql (Kont.)
      • Contoh
      <?php $nama_server = &quot;localhost&quot;; $nama_user = &quot;root&quot;; $password = &quot;&quot;; $database = &quot;Perpus&quot;; $id_mysql= mysql_connect ($nama_server,$nama_user,$password); if(! $id_mysql) die(&quot;Database MySQL tak dapat dibuka&quot;); if (! mysql_select_db($database,$id_mysql)) die(&quot;Database tak dalat dipilih&quot;); $hasil= mysql_query (&quot;SELECT nktlg, judul from buku order by judul&quot;,$id_mysql); ?>
    • Fungsi-fungsi MySql (Kont.)
      • Fungsi mysql_db_query
      • Bentuk:
      Menjalankan suatu permintaan terhadap suatu database mysql_db_query ( databases, permintaan, pengenal_hubungan )
    • Fungsi-fungsi MySql (Kont.)
      • Contoh
      <?php $nama_server = &quot;localhost&quot;; $nama_user = &quot;root&quot;; $password = &quot;&quot;; $database = &quot;Perpus&quot;; $id_mysql= mysql_connect ($nama_server,$nama_user,$password); if(! $id_mysql) die(&quot;Database MySQL tak dapat dibuka&quot;); if (! mysql_select_db($database,$id_mysql)) die(&quot;Database tak dalat dipilih&quot;); $query=&quot;SELECT nktlg, judul from buku order by judul&quot;; $hasil= mysql_db_query ($database,$query,$id_mysql); ?>
    • Fungsi-fungsi MySql (Kont.)
      • Fungsi mysql_num_rows
      • Bentuk:
      Memperoleh jumlah baris dari suatu hasil permintaan (query) yang menggunakan SELECT. mysql_num_rows ( pengenal_hasil )
    • Fungsi-fungsi MySql (Kont.)
      • Contoh
      <?php $nama_server = &quot;localhost&quot;; $nama_user = &quot;root&quot;; $password = &quot;&quot;; $database = &quot;Perpus&quot;; $id_mysql= mysql_connect ($nama_server,$nama_user,$password); if(! $id_mysql) die(&quot;Database MySQL tak dapat dibuka&quot;); if (! mysql_select_db($database,$id_mysql)) die(&quot;Database tak dalat dipilih&quot;); $query=&quot;SELECT nktlg, judul from buku order by judul&quot;; $hasil= mysql_query ($query,$id_mysql); $jbaris= mysql_num_rows ($hasil); ?>
    • Fungsi-fungsi MySql (Kont.)
      • Fungsi mysql_affected_rows
      • Bentuk:
      Memperoleh jumlah baris yang menggunakan operasi (query) INSERT, DELETE, dan UPDATE. mysql_affected_rows ( pengenal_hasil )
    • Fungsi-fungsi MySql (Kont.)
      • Contoh
      include (&quot;conect.inc.php&quot;); $query = &quot;UPDATE buku SET kdpeng = '$kdpeng', &quot; . &quot;kdpen = '$kdpen', judul = '$judul', Tahun = '$thn' &quot; . &quot;jumlah = '$jml' WHERE nktlg = '$nktlg'&quot;; $hasil= mysql_query ($query, $id_mysql); $baris= mysql_affected_rows ($hasil);
    • Fungsi-fungsi MySql (Kont.)
      • Fungsi mysql_num_fields
      • Bentuk:
      Memperoleh jumlah kolom pada suatu hasil permintaan (query). mysql_num_fields ( pengenal_hasil )
    • Fungsi-fungsi MySql (Kont.)
      • Contoh
      include (&quot;conect.inc.php&quot;); $query = “SELECT * FROM BUKU &quot;; $hasil= mysql_query ($query, $id_mysql); $kolom= mysql_num_fields ($hasil); Kolom=8 BUKU
    • Fungsi-fungsi MySql (Kont.)
      • Fungsi mysql_fetch_row
      • Bentuk:
      Membentuk suatu array yang berisi kolom dari sebuah baris pada suatu himpunan hasil. mysql_fetch_row ( pengenal_hasil )
    • Fungsi-fungsi MySql (Kont.)
      • Contoh
      include &quot;conect.inc.php&quot;; $hasil = mysql_query ( &quot;SELECT * FROM buku WHERE nktlg = '$nktlg'&quot;,$id_mysql); $baris = mysql_fetch_row ($hasil); if ($baris == FALSE) die(&quot;Tak ada data yang memenuhi&quot;); $nktlg = $baris[0]; $judul = $baris[1]; $kdklas = $baris[2]; $kdpeng = $baris[3]; $kdpen = $baris[4]; $tahun = $baris[5]; $jml = $baris[6];
    • Fungsi-fungsi MySql (Kont.)
      • Fungsi mysql_fetch_array
      • Bentuk:
      Mempunyai kegunaan sama dengan mysql_fetch_row , hanya saja setiap kolom disimpan dua kali pada array hasil. mysql_fetch_array ( pengenal_hasil )
    • Fungsi-fungsi MySql (Kont.)
      • Fungsi mysql_data_seek
      • Bentuk:
      Memindahkan pointer pada suatu himpunan hasil supaya menunjuk ke baris tertentu. mysql_data_seek ( pengenal_hasil,nomor_baris )
    • Contoh Selengkapnya (Studi Kasus)
      • Studi Kasus ini akan diambil sama dg akases data via ODBC Sistem Informasi Perpustakaan sebelumnya.
      • Pada kasus ini terdapat 3 (tiga) include file untuk web page yaitu:
        • Umum.inc
        • Otentic.inc
        • Connect.inc.php
    • Umum.inc <?php $nama_server = &quot;localhost&quot;; $nama_user = &quot;root&quot;; $password = &quot;&quot;; $database = &quot;perpus&quot;; function header_dinamis() { header(&quot;Expires: 10 Desember 2004 17:00:00 GMT&quot;); header(&quot;Last-Modified:&quot;. gmdate(&quot;D, d M Y M:i:s&quot;)); if ($SERVER_PROTOCOL == &quot;HTTP/0.1&quot;) header(&quot;Pragma: no-cache&quot;); else header(&quot;Cache-Control: no-cache, must-revalidate&quot;); } ?>
    • Connet.inc.php <?php $nama_server = &quot;localhost&quot;; $nama_user = &quot;root&quot;; $password = &quot;&quot;; $database = &quot;Perpus&quot;; $id_mysql=mysql_connect($nama_server,$nama_user,$password); if(! $id_mysql) die(&quot;Database MySQL tak dapat dibuka&quot;); if (! mysql_select_db($database,$id_mysql)) die(&quot;Database tak dalat dipilih&quot;); ?>
    • Otentik.inc <?php include &quot;umum.inc&quot;; function otentikasi($pemakai, $sandi) { global $nama_server, $nama_user, $password, $database; $id_mysql=mysql_pconnect($nama_sever, $nama_user, $password); if (! $id_mysql) return FALSE; if (! mysql_select_db($database, $id_mysql)) return FALSE; $hasil=mysql_query(&quot;SELECT * from user where STB='$pemakai'&quot;,$id_mysql);
    • Otentik.inc <?php include &quot;umum.inc&quot;; function otentikasi($pemakai, $sandi) { global $nama_server, $nama_user, $password, $database; $id_mysql=mysql_pconnect($nama_sever, $nama_user, $password); if (! $id_mysql) return FALSE; if (! mysql_select_db($database, $id_mysql)) return FALSE; $hasil=mysql_query(&quot;SELECT * from user where stb='$pemakai'&quot;,$id_mysql);
    • Otentik.inc (Kont.) if (! $hasil) return FALSE; $baris=mysql_fetch_row($hasil); $pass1=substr(md5($sandi),0,10); if ($baris[1]==$pass1) { return TRUE; } else { return FALSE; } } ?>
    • Entri Pengarang (pengar.php)
    • Entri Pengarang (pengar.php)  Kont. <?php include &quot;otentik.inc&quot;; session_start(); $sesi_user=$_SESSION[&quot;sesi_user&quot;]; $sesi_pass=$_SESSION[&quot;sesi_pass&quot;]; if (! otentikasi($sesi_user,$sesi_pass)) { header('WWW-Authenticate: Basic realm=&quot;Authentication System&quot;'); header('HTTP/1.0 401 Unauthorized'); echo &quot;You must enter a valid login ID and password to access this resourcen&quot;; exit(); } ?>
    • Entri Pengarang (pengar.php)  Kont. <html><head><title>Kota</title></head> <body bgcolor=&quot;#F5F5F5&quot;> <table border=&quot;5&quot; align=&quot;center&quot;> <th>PENGARANG BUKU</th> <tr><td> <form method=&quot;post&quot; action=&quot; save.pengar.php &quot;> <table> <tr> <td>Kode Pengarang</td> <td> <input type=&quot;text&quot; size=&quot;4&quot; name=&quot;kdpeng&quot; maxlength=&quot;4&quot;></td> </tr> <tr> <td>Nama Pengarang</td> <td> <input type=&quot;text&quot; size=&quot;35&quot; name=&quot;nmpeng&quot;></td> </tr> <tr> <td colspan=2 align=&quot;center&quot;><input type=&quot;submit&quot; value=&quot;Rekam&quot;>&nbsp;&nbsp;&nbsp;&nbsp <input type=&quot;Reset&quot; value=&quot;Batal&quot;></td> </tr> </table></form></td></tr></table> </body></html>
    • Save.pengar.php <html><body> <table border=1 align=&quot;center&quot;><tr><td align=&quot;center&quot;> <?php $kdpeng=$_POST['kdpeng']; $nmpeng=$_POST['nmpeng']; if (empty($kdpeng) or empty($nmpeng)) { print(&quot;<b><font color=red>Maaf</font></b><br>&quot;); print(&quot;Data <b>Pengarang</b> gagal diposting karena Tidak Lengkap</td>&quot;); print(&quot;<tr><td align=center><br><a href=&quot;pengar.php&quot;>Kembali ke Entri Pengarang</a><br></td><tr></table>&quot;); exit(); } include(&quot;conect.inc.php&quot;); $query=&quot;INSERT INTO pengarang (kdpeng,nmpeng) VALUES ('$kdpeng','$nmpeng')&quot;;
    • Save.pengar.php (Kont.) mysql_query ($query, $id_mysql); if ( mysql_affected_rows () >0) { print(&quot;Selamat<br>&quot;); print(&quot;Pengarang $nmpeng Telah SUKSES diCatat&quot;); } else { print(&quot;<font color=red>M a a f: Perekaman</font><br>&quot;); print(&quot;<br> Kode Pengarang = $kdpeng&quot;); print(&quot;<br> Nama Pengarang = $nmpeng<br><br>&quot;); print(&quot;Gagal dilakukan<br>&quot;); } mysql_close ($id_mysql); ?> <br><a href=&quot;pengar.php&quot;>Kembali ke Entri Pengarang</a> </td></tr></table> </body> </html>
    • SAMPAI JUMPA Di FINAL TEST TERIMAKASIH