Membuat Aplikasi Koneksi ke Oracle dengan PHP

Buat File db.php

<? // db.php ?>
<?
$db=”XE”;
$user=”system”;
$pass=”123″;
?>

<? //sql.php
$qmhs=”select * from mahasiswa”;
$qjmlmhs=”select count(*) from ($qmhs)”;
?>

<? //ora_db.php
class ora_db{
var $user,$pass,$db,$sql,$hasil,$kolom;
function konekdb(){
include “db.php”;
$this->user=$user;
$this->pass=$pass;
$this->db=$db;
return ocilogon($this->user,$this->pass,$this->db);
}
function sql($sql){
return ociparse($this->konekdb(),$sql);
}
function execute($hasil){
return ociexecute($hasil);
}
function hitungrow($sql){
$state=ociparse($this->konekdb(),$sql);
ociexecute($state);
ocifetch($state);
return ociresult($state,1);
}
function getarray($hasil){
return ocifetch($hasil);
}
function cols($hasil,$kolom){
return ociresult($hasil,$kolom);
}
function free($hasil){
return oci_free_statement($hasil);
}
}
?>

<? include “ora_db.php” ?>
<? //prj.php
class prj extends ora_db{
var $qmhs,$qjmlmhs,$edit;
function seleksimhs(){
include “sql.php”;
$this->qmhs=$qmhs;
return $this->sql($this->qmhs);
}
function jmlmhs(){
include “sql.php”;
$this->qjmlmhs=$qjmlmhs;
return $this->hitungrow($this->qjmlmhs);
}
function insertmhs($qmhs,$qjmlmhs){
return $this->sql(”insert into mahasiswa values(’$qmhs’,’$qjmlmhs’)”);
}
function seleksidmn($edit){
return $this->sql(”select * from mahasiswa where npm=’$edit’”);
}
function editmhs($qmhs,$qjmlmhs,$edit){
return $this->sql(”update mahasiswa set npm=’$qmhs’,nama=’$qjmlmhs’ where npm=’$edit’”);
}
}
?>

<? include “prj.php” ?>
<?
$obj=new prj;
$obj->konekdb();
$q=$obj->seleksimhs();
$obj->execute($q);
echo $obj->jmlmhs($q).” baris<br>”;
?>
<table border=1>
<tr>
<td>No. </td>
<td>Nama </td>
<td>Alamat</td>
<td>Edit</td>
</tr>
<?
$no=0;
while ($obj->getarray($q)){ $no++;
$npm=$obj->cols($q,1);
?>
<tr>
<td><?=$no?>.</td>
<td><?=$npm?></td>
<td><?=$obj->cols($q,2)?></td>
<td><a href=”Edit.php?npm=<?=$npm?>”>Edit</a></td>
</tr>
<? } $obj->free($q); ?>

Dikutip dari :http://samsonasik.wordpress.com/2007/11/18/php-connect-oracle/

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s