1 / 31

Pemrograman Web (database)

By. Rita Wiryasaputra. Pemrograman Web (database). Daftar Pustaka. Panduan Membuat Aplikasi Database dengan PHP, Syafii , Yogyakarta, Andi Offset, 2005 Membangun Website Dinamis dan Interaktif dengan Ms. Office FrontPage 2003,Jasmadi,Jakarta,ElexMedia,2005

altessa
Download Presentation

Pemrograman Web (database)

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. By. Rita Wiryasaputra Pemrograman Web (database)

  2. Daftar Pustaka • PanduanMembuatAplikasi Database dengan PHP, Syafii, Yogyakarta, Andi Offset, 2005 • Membangun Website DinamisdanInteraktifdengan Ms. Office FrontPage 2003,Jasmadi,Jakarta,ElexMedia,2005 • MembangunSitus Web dengan FrontPage XP, Djoko Pramono,Jakarta,ElexMedia,2002 • ASP untukOrangAwam, Wahidin, Maxikom, 2004 • Core JSF,3nd edition • Apress Beginning Spring 2 from Novice to Professional

  3. Fungsi PHP untuk MYSQL • mysql_connect → menghubungkan php dengan mysql • mysql_create_db → membuat database • mysql_close → menutup koneksi • mysql_query → mengirim query ke mysql • mysql_select_db → memilih database • Mysql_fetch_row → menampilkan hasil query dalam bentuk array • Mysql_fetch_array → menampilkan hasil query dalam bentuk array assosiatif • Mysql_num_rows → menghitung jumlah baris dari hasil query • Mysql_num_fields → menghitung jumlah kolom dari hasil query

  4. <!--nama file : d:\phpgenap\link.php dibuatoleh : Rita W. deskripsi : membuat database mhsmysqldengan script php --> <font size = 16> <? echo ("Pembuatan database mhs "); $link = mysql_connect("localhost","",""); if ($link) {print ("Connected successfully"); } else{echo "gagal";} mysql_create_db(‘dmhs') or die ("database tidakbisadicreate"); mysql_close($link); ?>

  5. Tabelmhs.php <!--nama file : d:\phpgenap\tabelmhs dibuatoleh : Rita W. deskripsi : membuattabel database denganmysql, php --> <font size = 16> <? echo("Pembuatantabeldatabase<br>"); $link = mysql_connect("localhost","",""); if ($link) {print ("Connected successfully"); } else{echo "gagal";} mysql_select_db(‘dmhs'); $querystr = "create table datamhs (nim char(5) not null primary key, namavarchar(10), jurusanvarchar(20))"; mysql_query ($querystr) or die (mysql_error()); mysql_close($link); ?>

  6. Tampilmhs.php <!--nama file : d:\phpgenap\tampilmhs dibuatoleh : Rita W. deskripsi : menampilkanisitabeldatamhs --> <font size = 16> <? Include (‘conector.php’); echo(“Menampilkanisitabeldatamhspada database mhs<br>"); mysql_select_db (‘dmhs'); $querystr = "select * from datamhs "; $query = mysql_query ($querystr) or die (mysql_error()); while ($row = mysql_fetch_row($query)) { echo ("$row[0] , $row[1] , $row[2] <br>");} mysql_close($link); ?>

  7. Tampilmhs.php (versi tabel) <!--nama file : c:\apache\htdocs\phpgenap\tampilmhs.php dibuat oleh : Rita W. deskripsi : menampilkan isi tabel datamhs --> <font size = 16> <? echo("Menampilkan isi tabel datamhs pada database mhs<br>"); $link = mysql_connect("localhost","","") or die ('Koneksi gagal'); mysql_select_db ('mhs'); $querystr = "select * from datamhs order by jurusan"; $query = mysql_query ($querystr) or die (mysql_error()); ?> <table border =3 > <tr> <td width="120" align="center"> <font size=16> nim </td> <td width="160" align="center"> <font size=16> nama </td> <td width="360" align="center"> <font size=16> jurusan</td> </tr>

  8. Lanjutan tampilmhs.php (versi tabel) <? while ($row = mysql_fetch_row($query)) { ?> <tr> <td width="120" align="center"> <font size=16> <? echo ("$row[0]"); ?> </td> <td width="160"> <font size=16> <? echo ("$row[1]"); ?> </td> <td> <font size=16> <? echo ("$row[2]"); }?> </tr></td> </table> <? mysql_close($link); ?>

  9. Forminput.html <!--nama file : c:\apache\htdocs\phpgenap\forminput.html dibuat oleh : Rita W. deskripsi : Form memasukkan isi data tabel datamhs --> <font size = 16> <body> <form action="input.php" method="get"> Form input data pada tabel datamhs dengan database mhs <br> Nim : <input type = "text" name="nim" style="font-size: 32" size="15"><br> Nama : <input type = "text" name="nama" style="font-size: 32" size="15"><br> Jurusan : <input type = "text" name="jrs" style="font-size: 32" size="15"> <hr> <input type= "submit" value="Proses" style="font-size: 24pt"> <input type= "reset" value="Batal" style="font-size: 24pt"> </form> </body>

  10. Input.php <!--nama file : c:\apache\htdocs\phpgenap\input.php dibuatoleh : Rita W. deskripsi : memasukkanisi data tabeldatamhsdenganantarmukaforminput.html --> <font size = 16> <? Include (‘conector.php’); $perintah = "insert into datamhs (nim,nama,jurusan) values('$nim','$nama','$jrs') "; $query = mysql_query ($perintah);

  11. Lanjutan input.php if (isset ($query)) { echo ("Selamat data telah ter-input"); echo ("<form action=forminput.html >"); echo ("<input type=submit value=input></form>"); echo ("<form action=tampilmhs.php method=get>"); echo ("<input type=submit value=lihat> </form>"); } else {echo ("Input gagal");} mysql_close($link); ?>

  12. Tampilmhs.php (modifikasi) <? echo ("$row[2]"); echo("<td><font size=16> <a href=\"edit.php?id=$row[0]\">ubah</a></td> "); echo("<td><font size=16> <a href=\"hapus.php?id=$row[0]\">hapus</a></td> "); }?> </tr></td> </table>

  13. Hapus.php <!--nama file : c:\apache\htdocs\phpgenap\hapus.php dibuat oleh : Rita W. deskripsi : menghapus isi data tabel datamhs dari tampilmhs.php --> <font size = 16> <? $link = mysql_connect("localhost","","") or die ('Koneksi gagal'); mysql_select_db ('mhs'); $perintah = "delete from datamhs where nim=$id "; //$id didapat dari skrip tampilmhs.php $query = mysql_query ($perintah); echo ("<form action=tampilmhs.php method=get>"); echo ("<input type=submit value=lihat> </form>"); mysql_close($link); ?>

  14. Conector.php <!--nama file : c:\apache\htdocs\phpgenap\conector.php dibuatoleh : Rita W. deskripsi : koneksimysqldengan database mhs --> <font size = 16> <? $link = mysql_connect("localhost",“root","") or die ('Koneksigagal'); mysql_select_db(‘dmhs'); ?> back

  15. Menuutama.php <!--nama file : c:\apache\htdocs\phpgenap\menuutama.php dibuat oleh : Rita W. deskripsi : Form menu utama --> <font size = 16> <html> <title>Sistem Informasi Mahasiswa (Mhs) </title> <body> <li><a href=forminput.html>Input data mahasiswa</a> <li><a href=tampilmhs.php>Menampilkan daftar mahasiswa</a> </body> </html>

  16. Statement Transact-SQL (DDL) • Create table : pembentukantabel Use dmhs; create tablemasterbarang (kodebarangint not null, jenisbarangvarchar(20) not null, merkvarchar(10) not null) Transact SQL- Rita W,ST.

  17. Alter Table : modifikasitabel Use dmhs; Alter tablemasterbarang Addjumlahint not null Alter tablemasterbarang Drop columnjumlah Alter tablemasterbarang Alter columnjumlah Transact SQL- Rita W,ST.

  18. Drop Table : menghapustabel Use dmhs; Drop tablemasterbarang Transact SQL- Rita W,ST.

  19. Insert : menambahkan baris pd tabel Insert into (nama tabel) (nama kolom) values nilai masukan Use northwind Insertinto territories values (98101,’seatle’,2) Transact SQL- Rita W,ST.

  20. Update : mengubah data dlm tabel Update nama tabel set nilai yg akan diubah where kondisi Use northwind Update territories set territorydescription = ‘downtown seattle’ where territoryid = 98101 Transact SQL- Rita W,ST.

  21. Delete : menghapus baris dr tabel Delete from nama tabel where kondisi Use northwind Delete from territories where territoryid = 98101 Transact SQL- Rita W,ST.

  22. Comment • -- • /* .......*/ Transact SQL- Rita W,ST.

  23. Statement Transact-SQL (DML) • Select : menampilkan data dlm baris/kolom dari tabel • Select nama kolom from nama tabel where kondisi Transact SQL- Rita W,ST.

  24. Use dmhs; Select nim, nama from datamhs where (nama like ‘Haris%' or nama like 'Meika%') order by namadesc Transact SQL- Rita W,ST.

  25. Menampilkan data daritabelPembeliandari database dmhs Select * from dmhs.pembelian Transact SQL- Rita W,ST.

  26. Aggregate, mengoperasikansejumlahnilaidenganmemberikanhasilnilaitunggal. Contohnya AVG,SUM,MIN,MAX,COUNT. Aggregate biasanyadisertakandlm Group by clause dari statement SELECT Transact SQL- Rita W,ST.

  27. SELECT count(oo1) FROMpembelian SELECT count(oo1) as 'jumlahbaris' FROM pembelian SELECT sum(oo1) FROM dmhs.`pembelian` SELECT min(oo1) FROM `pembelian` SELECT max(oo1) FROM `pembelian` SELECT avg(oo1) FROM `pembelian`

  28. SELECT idbarang,oo1, oo2, oo1*oo2 FROM pembelian SELECT idbarang,oo1, oo2,'Rupiah', (oo1*oo2) as 'jumlah pembayaran' FROM pembelian

  29. SELECT datamhs.nama, pembelian.min FROM dmhs.datamhs, dmhs.pembelian where datamhs.nim = pembelian.nim; SELECT t1.nama, t2.min FROM dmhs.datamhs as t1, dmhs.pembelian as t2 where t1.nim = t2.nim;

  30. SELECT nim, MAX(oo) FROM pembelianGROUP BY nim HAVING MAX(oo)>35; SELECT nim, MAX(oo) as maximal FROM pembelian GROUP BY nim HAVING MAX(oo)>95;

  31. ` area ` like ` java % ` Tanda bukan petik tunggal, tapi tanda di sebelah tombol angka 1 Agar dapat membedakan bahwa nama field tidak sama dengan reserved word MySql

More Related