create table demo(
id integer not null,
keterangan varchar2(50),
constraint pk_demo primary key(id)
)
Create table kategori(
kategori_id number not null,
kategori_nama varchar2(25),
constraint pk_kategori primary key(kategori_id))
Create table pengarang(
pengarang_id char(3) not null,
pengarang_nama varchar2(25),
constraint pk_pengarang primary key(pengarang_id))
Create table penerbit(
penerbit_id char(4) not null,
penerbit_nama varchar2(25),
constraint pk_penerbit primary key(penerbit_id))
Insert into penerbit(penerbit_id,penerbit_nama) values ('PB01','ANGKASA RAYA');
Insert into penerbit(penerbit_id,penerbit_nama) values ('PB02','SINAR ILMU ANGKASA')
Insert into penerbit(penerbit_id,penerbit_nama) values ('PB03','INTAN')
Insert into penerbit(penerbit_id,penerbit_nama) values ('PB04','INFORMATIKAN')
Insert into penerbit(penerbit_id,penerbit_nama) values ('PB05','CAHAYA ILMU PERSADA')
Insert into penerbit(penerbit_id,penerbit_nama) values ('PB06','SINAR RAYA')
Insert into penerbit(penerbit_id,penerbit_nama) values ('PB07','TIGA SEKAWAN')
Insert into penerbit(penerbit_id,penerbit_nama) values ('PB08','CIPTA ILMU')
Create table buku(
buku_isbn char(13) not null,
buku_judul varchar2(75),
penerbit_id char(4),
buku_tglterbit date,
buku_jmlhalaman number,
buku_deskripsi varchar2(1000),
constraint pk_buku primary key(buku_isbn),
constraint fk_buku_penerbit foreign key(penerbit_id) references penerbit(penerbit_id))
INSERT INTO BUKU values ('222-34222-1-0','Mudah belajar photoshop','PB01','02-Jul-2003',300,'')
INSERT INTO BUKU values ('222-34222-1-1','Panduan praktis menggunakan coreldraw','PB02','15-Mar-2004',400,'')
Create table link_buku_pengarang(
buku_isbn char(13) not null,
pengarang_id char(3) not null,
constraint pk_buku_pengarang primary key(buku_isbn,pengarang_id),
constraint fk_bp_buku foreign key(buku_isbn) references buku(buku_isbn),
constraint fk_bp_pengarang foreign key(pengarang_id) references pengarang(pengarang_id)
)
Create table link_buku_kategori(
buku_isbn char(13) not null,
kategori_id number not null,
constraint pk_buku_kategori primary key(buku_isbn,kategori_id),
constraint fk_bk_buku foreign key(buku_isbn) references buku(buku_isbn),
constraint fk_bk_kategori foreign key(kategori_id) references kategori(kategori_id)
)
create table mahasiswa(
npm integer not null,
nama varchar2(50),
constraint pk_mahasiswa primary key(npm)
)
CREATE TABLE TB_USER
( ID_USER VARCHAR2(5),
NAMA_USER VARCHAR2(25),
COMPANY_USER VARCHAR2(15),
CHANNEL_USER VARCHAR2(15),
LEVEL_USER VARCHAR2(15),
PASSWORD_USER VARCHAR2(15),
constraint pk_user primary key(id_user)
)
insert into tb_user values('00001','Anju','LNFM','Penerbit','All','Anju')
insert into tb_user values('00002','Faisal','LNFM','Penerbit','Lihat','Faisal')
Rabu, 19 Juni 2013
Latihan PHP dengan Oracle
http://www.scribd.com/doc/23801302/Modul-Php-Oracle
Latihan-1:
-------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\welcome.php-->
<?php
echo "<h1>Welcome to PHP Programming!</h1>";
?>
Latihan-2:
-------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\oraconn.php-->
<?php
$username="anju";
$password="anju";
$dbname="localhost/XE";
$c=oci_connect($username, $password, $dbname);
if (!$c) {
echo "Koneksi ke server database gagal dilakukan";
exit();
}else{
echo "Koneksi ke server database sukses";
}
?>
Latihan-3a:
-------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_select.php-->
<?php
$db_conn= ocilogon("anju","anju","XE");
$query = "SELECT * FROM BUKU";
$parsed = ociparse($db_conn, $query);
ociexecute($parsed);
$nrows = ocifetchstatement($parsed, $results);
for ($i=0; $i<$nrows; $i++) {
echo " ".$results ["BUKU_ISBN"][$i]." ";
echo " ".$results ["BUKU_JUDUL"][$i]." ";
echo " ".$results ["BUKU_JMLHALAMAN"][$i].""; }
?>
Latihan-3b:
-------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_select1.php-->
<html>
<head>
<title> PHP Oracle</title>
</head>
<body>
<h2>Demo menampilkan data dari database ke halaman web</h2>
<?php
include("oraconn.php");
$query="select
buku_isbn,
buku_judul,
buku_jmlhalaman
from buku order by buku_isbn";
$statemen=oci_parse($c,$query);
oci_execute($statemen);
echo"<p>query: $query</p>";
echo"<p><strong>hasil query:</strong></p>";
while($baris=oci_fetch_array($statemen))
{
echo $baris['BUKU_ISBN'].
" - ".
$baris['BUKU_JUDUL'].
" - ".
$baris['BUKU_JMLHALAMAN'].
"<br/>";
}
oci_free_statement($statemen);
oci_close($c);
?>
</body>
</html>
Latihan-3C:
----------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_select2.php-->
<?php
include("oraconn.php");
echo"Daftar Buku<hr><p></p>
<table border=1 cellpadding=4 cellspacing=0>
<tr bgcolor='#ccc'><td>ISBN</td><td>Title</td><td>Jml_Halaman</td></tr>";
$query="select * from BUKU order by BUKU_ISBN";
$statmen=oci_parse($c,$query);
oci_execute($statmen,OCI_DEFAULT);
while($data=oci_fetch_array($statmen,OCI_BOTH)){
echo"<tr><td>".$data['BUKU_ISBN']."</td><td>".$data['BUKU_TITLE']."</td><td>".$data['BUKU_JMLHALAMAN']."</td></tr>";
}
echo"</table>";
oci_free_statement($statmen);
oci_close($c);
?>
Latihan-4:
----------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_aplikasi.php-->
<?php
//$c=oci_connect("anju","anju","XE");
include("oraconn.php");
echo"MASTER USER <hr><p></p>";
//if($_GET['menu']=='')
$vMenu=$_GET['menu'];
if ($vMenu=='')
{
echo"<a href='?menu=tambah_data'><input type=submit value='Tambah'></a><p></p>
<table border=1 cellpadding=4 cellspacing=0>
<tr bgcolor='#ccc'><td>ID</td><td>Nama</td><td>Company</td><td>Channel</td><td>Level</td><td>Password</td><td>Edit</td><td>Hapus</td></tr>";
$query="select * from tb_user";
$statmen=oci_parse($c,$query);
oci_execute($statmen,OCI_DEFAULT);
while($data=oci_fetch_array($statmen,OCI_BOTH)){
echo"<tr><td>".$data['ID_USER']."</td><td>".$data['NAMA_USER']."</td><td>".$data['COMPANY_USER']."</td><td>".$data['CHANNEL_USER']."</td><td>".$data['LEVEL_USER']."</td><td>".$data['PASSWORD_USER']."</td><td><a href='?menu=edit&id=$data[ID_USER]'>edit</a></td><td><a href=\"aksi.php?act=hapus_data&id=$data[ID_USER]\" onclick=\"return confirm('Yakin Mau Hapus $data[NAMA_USER]??')\"'>Hapus</a></td></tr>";
}
echo"</table>";
oci_free_statement($statmen);
}
//if($_GET['menu']=='edit'){
if ($vMenu=='edit'){
$sql="select * from TB_USER where id_USER='$_GET[id]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
$data=oci_fetch_array($statment);
echo"
<form method=POST action='aksi.php?act=edit_data'>
<input type=hidden name='id_ubah' value='$data[ID_USER]'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>ID</td><td><input type=text name='ID_UBAH' value='$data[ID_USER]' size=1 disabled></td></tr>
<tr><td>Nama</td><td><input type=text name='NAMA_FUBAH' value='$data[NAMA_USER]'></td><tr>
<tr><td>Company</td><td><input type=text name='COMPANY_FUBAH' value='$data[COMPANY_USER]'></td><tr>
<tr><td>Channel</td><td><input type=text name='CHANNEL_FUBAH' value='$data[CHANNEL_USER]'></td><tr>
<tr><td>Level</td><td><input type=text name='LEVEL_FUBAH' value='$data[LEVEL_USER]'></td><tr>
<tr><td>Password</td><td><input type=text name='PASSWORD_FUBAH' value='$data[PASSWORD_USER]'></td><tr>
<tr><td></td><td><input type=submit value='Update'></td><tr>
</table>
</form>
";
}
//if($_GET['menu']=='tambah_data'){
if ($vMenu=='tambah_data'){
echo"
<form method=POST action='aksi.php?act=tambah_data'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>ID</td><td><input type=text name='ID_TMP'></td></tr>
<tr><td>NAMA</td><td><input type=text name='NAMA_TMP'></td></tr>
<tr><td>COMPANY</td><td><input type=text name='COMPANY_TMP'></td></tr>
<tr><td>CHANNEL</td><td><input type=text name='CHANNEL_TMP'></td></tr>
<tr><td>LEVEL</td><td><input type=text name='LEVEL_TMP'></td></tr>
<tr><td>PASSWORD</td><td><input type=text name='PASSWORD_TMP'></td></tr>
<tr><td></td><td><input type=submit value='SIMPAN'></td><tr>
</table>
</form>
";
}
?>
----------------------------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\aksi.php-->
<?php
$c=oci_connect("anju","anju","XE");
$act=$_GET['act'];
if($act=='edit_data'){
$sql="update TB_USER set NAMA_USER='$_POST[NAMA_FUBAH]',COMPANY_USER='$_POST[COMPANY_FUBAH]',CHANNEL_USER='$_POST[CHANNEL_FUBAH]',
LEVEL_USER='$_POST[LEVEL_FUBAH]',PASSWORD_USER='$_POST[PASSWORD_FUBAH]' where ID_USER='$_POST[id_ubah]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:latihan_aplikasi.php');
}
if($act=='tambah_data'){
$sql="insert into TB_USER(ID_USER,NAMA_USER,COMPANY_USER,CHANNEL_USER,LEVEL_USER,PASSWORD_USER)
values('$_POST[ID_TMP]','$_POST[NAMA_TMP]','$_POST[COMPANY_TMP]','$_POST[CHANNEL_TMP]','$_POST[LEVEL_TMP]','$_POST[PASSWORD_TMP]')";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:latihan_aplikasi.php');
}
if($act=='hapus_data'){
$sql="delete from TB_USER where ID_USER='$_GET[id]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:latihan_aplikasi.php');
}
?>
Latihan-5:
----------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_login.php-->
<?php
@session_start();
unset($_SESSION['nama_user']);
if (ISSET($_SESSION['nama_user']))
{
header ("location:index.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login</title>
<style type="text/css">
<!--
.style1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 36px;
color: #FF3300;
}
.style4 {font-family: Geneva, Arial, Helvetica, sans-serif; font-weight: bold; }
-->
</style>
</head>
<body>
<center>
<form id="form1" name="form1" method="post" action="proses_login.php">
<table width="400" border="1">
<tr>
<td colspan="3" align="center" valign="top" bgcolor="#000000"><span class="style1">Login</span></td>
</tr>
<tr>
<td width="100"><span class="style4">Username</span></td>
<td width="3"><span class="style4">:</span></td>
<td width="275"><input name="nama_user" type="text" id="nama_user" /></td>
</tr>
<tr>
<td><span class="style4">Password</span></td>
<td><span class="style4">:</span></td>
<td><input name="password_user" type="password" id="password_user" /></td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" name="Submit" value="Login" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>
----------------------------------------------------------------------------
<<!--C:\Apache2.2\htdocs\php-oracle\proses_login.php-->
<?php @session_start();
//koneksi database
include ("oraconn.php");
$username = $_POST['nama_user'];
$password = $_POST['password_user'];
$query = "SELECT * FROM TB_USER WHERE nama_user='$username' and password_user='$password'";
$hasil = oci_parse($c,$query);
$data = oci_execute($hasil,OCI_DEFAULT);
//Validasi Data dari form dengan database
if ($data >= 1)
{
$_SESSION['nama_user']=$username;
header("location:index.php");
}
else
{
echo "<script type='text/javascript'>alert('Maaf! Data yang anda masukan tidak benar');document.location='login.php'</script>";
}
?>
----------------------------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\index.php-->
<?php @session_start();
if (ISSET($_SESSION['nama_user']))
{
echo "Login Berhasil.."."<br />";
echo "Anda Login Sebagai"." : ".$_SESSION['nama_user']."<br />";
echo "<a href='latihan_login.php'>Logout</a>"."<br />";
}
else
{
unset($_SESSION['nama_user']);
echo "<script type='text/javascript'>alert('Silahkan Login dahulu!');document.location='latihan_login.php'</script>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Index</title>
<style type="text/css">
<!--
.style4 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 36px;
color: #FF3300;
}
-->
</style>
</head>
<body>
<span class="style4">Welcome...</span>
</body>
</html>
Latihan-1:
-------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\welcome.php-->
<?php
echo "<h1>Welcome to PHP Programming!</h1>";
?>
Latihan-2:
-------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\oraconn.php-->
<?php
$username="anju";
$password="anju";
$dbname="localhost/XE";
$c=oci_connect($username, $password, $dbname);
if (!$c) {
echo "Koneksi ke server database gagal dilakukan";
exit();
}else{
echo "Koneksi ke server database sukses";
}
?>
Latihan-3a:
-------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_select.php-->
<?php
$db_conn= ocilogon("anju","anju","XE");
$query = "SELECT * FROM BUKU";
$parsed = ociparse($db_conn, $query);
ociexecute($parsed);
$nrows = ocifetchstatement($parsed, $results);
for ($i=0; $i<$nrows; $i++) {
echo " ".$results ["BUKU_ISBN"][$i]." ";
echo " ".$results ["BUKU_JUDUL"][$i]." ";
echo " ".$results ["BUKU_JMLHALAMAN"][$i].""; }
?>
Latihan-3b:
-------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_select1.php-->
<html>
<head>
<title> PHP Oracle</title>
</head>
<body>
<h2>Demo menampilkan data dari database ke halaman web</h2>
<?php
include("oraconn.php");
$query="select
buku_isbn,
buku_judul,
buku_jmlhalaman
from buku order by buku_isbn";
$statemen=oci_parse($c,$query);
oci_execute($statemen);
echo"<p>query: $query</p>";
echo"<p><strong>hasil query:</strong></p>";
while($baris=oci_fetch_array($statemen))
{
echo $baris['BUKU_ISBN'].
" - ".
$baris['BUKU_JUDUL'].
" - ".
$baris['BUKU_JMLHALAMAN'].
"<br/>";
}
oci_free_statement($statemen);
oci_close($c);
?>
</body>
</html>
Latihan-3C:
----------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_select2.php-->
<?php
include("oraconn.php");
echo"Daftar Buku<hr><p></p>
<table border=1 cellpadding=4 cellspacing=0>
<tr bgcolor='#ccc'><td>ISBN</td><td>Title</td><td>Jml_Halaman</td></tr>";
$query="select * from BUKU order by BUKU_ISBN";
$statmen=oci_parse($c,$query);
oci_execute($statmen,OCI_DEFAULT);
while($data=oci_fetch_array($statmen,OCI_BOTH)){
echo"<tr><td>".$data['BUKU_ISBN']."</td><td>".$data['BUKU_TITLE']."</td><td>".$data['BUKU_JMLHALAMAN']."</td></tr>";
}
echo"</table>";
oci_free_statement($statmen);
oci_close($c);
?>
Latihan-4:
----------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_aplikasi.php-->
<?php
//$c=oci_connect("anju","anju","XE");
include("oraconn.php");
echo"MASTER USER <hr><p></p>";
//if($_GET['menu']=='')
$vMenu=$_GET['menu'];
if ($vMenu=='')
{
echo"<a href='?menu=tambah_data'><input type=submit value='Tambah'></a><p></p>
<table border=1 cellpadding=4 cellspacing=0>
<tr bgcolor='#ccc'><td>ID</td><td>Nama</td><td>Company</td><td>Channel</td><td>Level</td><td>Password</td><td>Edit</td><td>Hapus</td></tr>";
$query="select * from tb_user";
$statmen=oci_parse($c,$query);
oci_execute($statmen,OCI_DEFAULT);
while($data=oci_fetch_array($statmen,OCI_BOTH)){
echo"<tr><td>".$data['ID_USER']."</td><td>".$data['NAMA_USER']."</td><td>".$data['COMPANY_USER']."</td><td>".$data['CHANNEL_USER']."</td><td>".$data['LEVEL_USER']."</td><td>".$data['PASSWORD_USER']."</td><td><a href='?menu=edit&id=$data[ID_USER]'>edit</a></td><td><a href=\"aksi.php?act=hapus_data&id=$data[ID_USER]\" onclick=\"return confirm('Yakin Mau Hapus $data[NAMA_USER]??')\"'>Hapus</a></td></tr>";
}
echo"</table>";
oci_free_statement($statmen);
}
//if($_GET['menu']=='edit'){
if ($vMenu=='edit'){
$sql="select * from TB_USER where id_USER='$_GET[id]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
$data=oci_fetch_array($statment);
echo"
<form method=POST action='aksi.php?act=edit_data'>
<input type=hidden name='id_ubah' value='$data[ID_USER]'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>ID</td><td><input type=text name='ID_UBAH' value='$data[ID_USER]' size=1 disabled></td></tr>
<tr><td>Nama</td><td><input type=text name='NAMA_FUBAH' value='$data[NAMA_USER]'></td><tr>
<tr><td>Company</td><td><input type=text name='COMPANY_FUBAH' value='$data[COMPANY_USER]'></td><tr>
<tr><td>Channel</td><td><input type=text name='CHANNEL_FUBAH' value='$data[CHANNEL_USER]'></td><tr>
<tr><td>Level</td><td><input type=text name='LEVEL_FUBAH' value='$data[LEVEL_USER]'></td><tr>
<tr><td>Password</td><td><input type=text name='PASSWORD_FUBAH' value='$data[PASSWORD_USER]'></td><tr>
<tr><td></td><td><input type=submit value='Update'></td><tr>
</table>
</form>
";
}
//if($_GET['menu']=='tambah_data'){
if ($vMenu=='tambah_data'){
echo"
<form method=POST action='aksi.php?act=tambah_data'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>ID</td><td><input type=text name='ID_TMP'></td></tr>
<tr><td>NAMA</td><td><input type=text name='NAMA_TMP'></td></tr>
<tr><td>COMPANY</td><td><input type=text name='COMPANY_TMP'></td></tr>
<tr><td>CHANNEL</td><td><input type=text name='CHANNEL_TMP'></td></tr>
<tr><td>LEVEL</td><td><input type=text name='LEVEL_TMP'></td></tr>
<tr><td>PASSWORD</td><td><input type=text name='PASSWORD_TMP'></td></tr>
<tr><td></td><td><input type=submit value='SIMPAN'></td><tr>
</table>
</form>
";
}
?>
----------------------------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\aksi.php-->
<?php
$c=oci_connect("anju","anju","XE");
$act=$_GET['act'];
if($act=='edit_data'){
$sql="update TB_USER set NAMA_USER='$_POST[NAMA_FUBAH]',COMPANY_USER='$_POST[COMPANY_FUBAH]',CHANNEL_USER='$_POST[CHANNEL_FUBAH]',
LEVEL_USER='$_POST[LEVEL_FUBAH]',PASSWORD_USER='$_POST[PASSWORD_FUBAH]' where ID_USER='$_POST[id_ubah]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:latihan_aplikasi.php');
}
if($act=='tambah_data'){
$sql="insert into TB_USER(ID_USER,NAMA_USER,COMPANY_USER,CHANNEL_USER,LEVEL_USER,PASSWORD_USER)
values('$_POST[ID_TMP]','$_POST[NAMA_TMP]','$_POST[COMPANY_TMP]','$_POST[CHANNEL_TMP]','$_POST[LEVEL_TMP]','$_POST[PASSWORD_TMP]')";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:latihan_aplikasi.php');
}
if($act=='hapus_data'){
$sql="delete from TB_USER where ID_USER='$_GET[id]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:latihan_aplikasi.php');
}
?>
Latihan-5:
----------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\latihan_login.php-->
<?php
@session_start();
unset($_SESSION['nama_user']);
if (ISSET($_SESSION['nama_user']))
{
header ("location:index.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login</title>
<style type="text/css">
<!--
.style1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 36px;
color: #FF3300;
}
.style4 {font-family: Geneva, Arial, Helvetica, sans-serif; font-weight: bold; }
-->
</style>
</head>
<body>
<center>
<form id="form1" name="form1" method="post" action="proses_login.php">
<table width="400" border="1">
<tr>
<td colspan="3" align="center" valign="top" bgcolor="#000000"><span class="style1">Login</span></td>
</tr>
<tr>
<td width="100"><span class="style4">Username</span></td>
<td width="3"><span class="style4">:</span></td>
<td width="275"><input name="nama_user" type="text" id="nama_user" /></td>
</tr>
<tr>
<td><span class="style4">Password</span></td>
<td><span class="style4">:</span></td>
<td><input name="password_user" type="password" id="password_user" /></td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" name="Submit" value="Login" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>
----------------------------------------------------------------------------
<<!--C:\Apache2.2\htdocs\php-oracle\proses_login.php-->
<?php @session_start();
//koneksi database
include ("oraconn.php");
$username = $_POST['nama_user'];
$password = $_POST['password_user'];
$query = "SELECT * FROM TB_USER WHERE nama_user='$username' and password_user='$password'";
$hasil = oci_parse($c,$query);
$data = oci_execute($hasil,OCI_DEFAULT);
//Validasi Data dari form dengan database
if ($data >= 1)
{
$_SESSION['nama_user']=$username;
header("location:index.php");
}
else
{
echo "<script type='text/javascript'>alert('Maaf! Data yang anda masukan tidak benar');document.location='login.php'</script>";
}
?>
----------------------------------------------------------------------------
<!--C:\Apache2.2\htdocs\php-oracle\index.php-->
<?php @session_start();
if (ISSET($_SESSION['nama_user']))
{
echo "Login Berhasil.."."<br />";
echo "Anda Login Sebagai"." : ".$_SESSION['nama_user']."<br />";
echo "<a href='latihan_login.php'>Logout</a>"."<br />";
}
else
{
unset($_SESSION['nama_user']);
echo "<script type='text/javascript'>alert('Silahkan Login dahulu!');document.location='latihan_login.php'</script>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Index</title>
<style type="text/css">
<!--
.style4 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 36px;
color: #FF3300;
}
-->
</style>
</head>
<body>
<span class="style4">Welcome...</span>
</body>
</html>
TUTORIAL PHP ORACLE
Oracle
http://otn.oracle.com/xe
Oracle adalah pioner dalam dunia RDBMS. Dan sampai saat ini masih banyak digunakan , terutama perusahaan –perusahaan besar untuk menyimpan dan mengelola data perusahaan
NotePad++
http://notepad-plus-plus.org/download/.
Aplikasi editor coding gratisan dari Notepad
Apache
http://httpd.apache.org
Aplikasi Web Server
PHP
Sofware coding untuk halaman web
INSTALLATION ORACLE +
NOTEPAD ++
1. Jalankan file oracleXEUniv.exe
2. Hilangkan tanda checklist pada opsi Launch the Database homepage
3. TEST ING or Exerciseà Login : system
Password : manager
Create : user dan table
NotePad++
Jalankan file npp.6.2.3.Installer
Oracle
http://otn.oracle.com/xe 1. Jalankan file oracleXEUniv.exe
2. Hilangkan tanda checklist pada opsi Launch the Database homepage
3. TEST ING or Exerciseà Login : system
Password : manager
Create : user dan table
NotePad++
Jalankan file npp.6.2.3.Installer
INSTALLATION
APACHE (http://www.apache.org)
1. Jalankan file httpd-2.2.16-win32-x86-openssl-0.9.8o
2. Pada ND dan SD isi/ketik localhost dan pada Admin „s Email Address
isi/ketik me@localhost, kemudian pilih/klik opsi “for all users”
3. Change Folder menjadi c:\Apache2.2\
4. Setelah installasi finish : Masuk ke menu all program pada windows.
Pilih/klik Apache HTTP Server 2.2, kemudian klik Configure Apache Server
dan Edit the apache httpd.conf configuration file Atau pada Xampp\apache\conf\httpd.ini
5. Pada halaman httpd.conf , cari dan rubah isi dari Document Root dan DirectoryIndex
menjadi sbb : Document Root “C:/Apache2.2/htdocs”
DirectoryIndex index.php index.html
Untuk menjalankan PHP dibutuhkan Web Server (salah satunya “Apache”)
6. Masih pada halaman Edit the apache httpd.conf configuration file, cari dan lengkapi isi
<IfModule mime_module> menjadi sbb : <IfModule mime_module>
AddType application/x-compress .Z AddType application/x-gzip .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php-source .phps
7. Simpan 8. Apache di Restart 9. TESTING
http://localhost atau http://127.0.0.1 7. HASIL “It works!”
PHP With Apache
1. Matikan service Apache2. Jalankan file php-5.2.14-win32-installer3. Change folder c:\php\4. Pilih Apache 2.2.x Module5. Isikan C:\Apache 2.2\conf\6. Pilih extensions , modul Oracle (10) dan PDO|Oracle 10g client and above7. Configurasi atau hilangkan tanda ; pada : C:\php\php.ini Baris 342 : error_reporting = E_ALL & ~E_NOTICE Baris 373 : display_errors = On Baris 496 : magic_quotes_gpc = On Baris 535 : doc_root = “C:/Apache2.2/htdocs”8. Copy file php5ts.dll dari c:\php ke c:\Apache2.2\bin9. Buat folder php-oracle pada c:\Apache2.2\htdocs
PHP with Xampp
1. Matikan service Apache2. Jalankan file php-5.2.14-win32-installer3. Change folder c:\php\4. Pilih Apache 2.2.x Module5. Isikan C:\Xampp\Apache \conf\6. Pilih extensions , modul Oracle (10) dan PDO|Oracle 10g client and above7. Configurasi atau hilangkan tanda ; pada : C:\php\php.ini Baris 342 : error_reporting = E_ALL & ~E_NOTICE Baris 373 : display_errors = On Baris 496 : magic_quotes_gpc = On Baris 535 : doc_root = “C:/Xampp/htdocs”8. Copy file php5ts.dll dari c:\php ke c:\Xampp\Apache2.2\bin9. Buat folder php-oracle pada c:\Xampp\htdocs
TESTING
Menampilkan “Welcome to PHP Programming”Dari web browser http://localhost/php-oracle/welcome.php
Caranya adalah :
1. Tuliskan kode program tersebut dibawah ini dengan NotePad++ dan simpan dengan nama
“welcome.php” pada folder
Pengguna Apache : C:/Apache2.2/htdocs/php-oracle <?php echo “<h1>Welcome to PHP Programming!</h1>”; ?>
Pengguna XAMPP: C:/Apache2.2/htdocs/php-oracle <?php echo “<h1>Welcome to PHP Programming!</h1>”; ?>
2. Start Apache dan Masuk ke web browser http://localhost/php- oracle/welcome.php
1. DML (INSERT/ISI TABLE)
INSERT INTO BUKU VALUES („222-34222-1-0‟, ‟Mudah belajar photoshop‟, 300)
INSERT INTO BUKU VALUES („222-34222-1-1‟, ‟Panduan praktis menggunakan
coreldraw‟, 400)
SELECT Max, Min, Count, |,
2 .DML (SELECT/TAMPILKAN ISI TABLE)
Order by Asc, Desc
ALTER TABLE BUKU
ADD CONSTRAINT FK_BUKU
PRIMARY KEY (BUKU_ISBN)
SELECT * FROM BUKU
DML (UPDATE/UBAH ISI TABLE)
UPDATE BUKU SET BUKU_JMLHALAMAN=500
WHERE BUKU_ISBN= „222-34222-1-1‟
2 .DML (SELECT/TAMPILKAN ISI TABLE)
Order by Asc, Desc
ALTER TABLE BUKU
ADD CONSTRAINT FK_BUKU
PRIMARY KEY (BUKU_ISBN)
SELECT * FROM BUKU
DML (UPDATE/UBAH ISI TABLE)
UPDATE BUKU SET BUKU_JMLHALAMAN=500
WHERE BUKU_ISBN= „222-34222-1-1‟
ALTER TABLE BUKU
ADD CONSTRAINT FK_P FOREIGN KEY (ID_PENGARANG)
3.DML (DELETE/HAPUS ISI TABLE)
DELETE BUKU
REFERENCES PENGARANG (PENGARANG)
WHERE BUKU_ISBN= „222-34222-1-0‟
BUKU_ISBN 222-34222-1-0
BUKU_JUDUL Mudah belajar photoshop
BUKU_JMLHALAMAN 300
ALTER TABLE buku RENAME
COLUMN pengarang TO buku_pengarang
ALTER TABLE buku DROP COLUMN pengarang
Add , modify, rename and drop Column
ALTER TABLE BUKU ADD PENGARANG
BUKU_PENGARANG VARCHAR2(75)
ALTER TABLE BUKU MODIFY PENGARANG BUKU_PENGARANG VARCHAR2(100)
Integritas data
ALTER TABLE BUKU ADD CONSTRAINT PK_BUKU PRIMARY KEY (BUKU_ISBN)
PURGE RECYCLEBIN Rename and Drop table PURGE DBA_RECYCLEBIN
PURGE USER_RECYCLEBIN
DROP TABLE BUKU Rename BUKU to buku1
Solution : Sistem Informasi Percetakan PT XYZ
1. : Bangun koneksi antara PHP dan ORACLE
<!--Nama File: oraconn.php-->
<?php
$username="anju";
$password="anju";
$dbname="localhost/XE";
$c=oci_connect($username, $password, $dbname);
if (!$c) {
echo "Koneksi ke server database gagal dilakukan";
exit();
}else{
echo "Koneksi ke server database sukses";
}
?>
2. : PHP Programming <!--Nama File: latihan_select.php-->
<?php
$db_conn= ocilogon("anju","anju","XE");
$query = "SELECT * FROM BUKU";
$parsed = ociparse($db_conn, $query);
ociexecute($parsed);
$nrows = ocifetchstatement($parsed, $results);
for ($i=0; $i<$nrows; $i++) {
echo " ".$results [“BUKU_ISBN"][$i]." ";
echo " ".$results [“BUKU_JUDUL"][$i]." ";
echo " ".$results [“BUKU_JMLHALAMAN"][$i].""; } ?>
PHP Programming
<!--Nama File: latihan_select1.php-->
<title> PHP Oracle</title>
</head>
<body>
<h2>Demo menampilkan data dari database ke halaman
web</h2>
<?php
include("oraconn.php");
$query="select
buku_isbn,
buku_judul,
buku_jmlhalaman
from buku order by buku_isbn";
$statemen=oci_parse($c,$query);
oci_execute($statemen);
echo"<p>query: $query</p>";
echo"<p><strong>hasil query:</strong></p>";
while($baris=oci_fetch_array($statemen))
{
echo $baris['BUKU_ISBN'].
" - ".
$baris['BUKU_JUDUL'].
" - ".
$baris['BUKU_JMLHALAMAN'].
"<br/>";
}
oci_free_statement($statemen);
oci_close($c);
?>
</body>
</html>
ADD CONSTRAINT FK_P FOREIGN KEY (ID_PENGARANG)
3.DML (DELETE/HAPUS ISI TABLE)
DELETE BUKU
REFERENCES PENGARANG (PENGARANG)
WHERE BUKU_ISBN= „222-34222-1-0‟
BUKU_ISBN 222-34222-1-0
BUKU_JUDUL Mudah belajar photoshop
BUKU_JMLHALAMAN 300
ALTER TABLE buku RENAME
COLUMN pengarang TO buku_pengarang
ALTER TABLE buku DROP COLUMN pengarang
Add , modify, rename and drop Column
ALTER TABLE BUKU ADD PENGARANG
BUKU_PENGARANG VARCHAR2(75)
ALTER TABLE BUKU MODIFY PENGARANG BUKU_PENGARANG VARCHAR2(100)
Integritas data
ALTER TABLE BUKU ADD CONSTRAINT PK_BUKU PRIMARY KEY (BUKU_ISBN)
PURGE RECYCLEBIN Rename and Drop table PURGE DBA_RECYCLEBIN
PURGE USER_RECYCLEBIN
DROP TABLE BUKU Rename BUKU to buku1
Solution : Sistem Informasi Percetakan PT XYZ
1. : Bangun koneksi antara PHP dan ORACLE
<!--Nama File: oraconn.php-->
<?php
$username="anju";
$password="anju";
$dbname="localhost/XE";
$c=oci_connect($username, $password, $dbname);
if (!$c) {
echo "Koneksi ke server database gagal dilakukan";
exit();
}else{
echo "Koneksi ke server database sukses";
}
?>
2. : PHP Programming <!--Nama File: latihan_select.php-->
<?php
$db_conn= ocilogon("anju","anju","XE");
$query = "SELECT * FROM BUKU";
$parsed = ociparse($db_conn, $query);
ociexecute($parsed);
$nrows = ocifetchstatement($parsed, $results);
for ($i=0; $i<$nrows; $i++) {
echo " ".$results [“BUKU_ISBN"][$i]." ";
echo " ".$results [“BUKU_JUDUL"][$i]." ";
echo " ".$results [“BUKU_JMLHALAMAN"][$i].""; } ?>
PHP Programming
<!--Nama File: latihan_select1.php-->
<title> PHP Oracle</title>
</head>
<body>
<h2>Demo menampilkan data dari database ke halaman
web</h2>
<?php
include("oraconn.php");
$query="select
buku_isbn,
buku_judul,
buku_jmlhalaman
from buku order by buku_isbn";
$statemen=oci_parse($c,$query);
oci_execute($statemen);
echo"<p>query: $query</p>";
echo"<p><strong>hasil query:</strong></p>";
while($baris=oci_fetch_array($statemen))
{
echo $baris['BUKU_ISBN'].
" - ".
$baris['BUKU_JUDUL'].
" - ".
$baris['BUKU_JMLHALAMAN'].
"<br/>";
}
oci_free_statement($statemen);
oci_close($c);
?>
</body>
</html>
Langganan:
Postingan (Atom)