PhP connect Oracle

10 06 2008

Pertama, kita buat table di oracle, contoh table mahasiswa, berisi npm dan nama.
Kita ubah konfigurasi PHP-nya, di apache\bin\php.ini, seperti berikut :
bagian yang berhubungan sama oracle dan oci, “;”\comment nya dihilangkan..

Code:
extension=php_oracle.dll
extension=php_oci8.dll
;extension=php_oggvorbis.dll
extension=php_openssl.dll
;extension=php_parsekit.dll
extension=php_pdf.dll
extension=php_pdo.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll

————

Restart apache…(kalau perlu restart komputer)
—————
Selanjutnya, kita buat file phpnya :

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


—————————

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


—————————–

Code:
—————————-
<? //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);
}
}
?>


——————————

Code:
<? 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’”);
}
}
?>

—————————-

Code:
<? 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); ?>

…………………………………………………….

Iklan

Aksi

Information

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




%d blogger menyukai ini: