Syntax Connect

13 06 2008

<?
$konek = mysql_connect(“localhost”,”root”,””) or die (“Belum konek ama mysqlnya” . mysql_error);
$sql = mysql_select_db(“dist”);
?>





Syntax Delete

13 06 2008

<?
include”konek.php”;
$sql=”delete from member where member=’$data'”;
$laksanakan=mysql_query($sql);
if ($laksanakan){
header(“location:tampil.php”);
}else{
echo “data gagal dihapus”;
}
?>





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

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





Syntax Tampil

9 06 2008

<?
$member=$_POST[“member”];
$pass=$_POST[“pass”];
$nama=$_POST[“nama”];
$alamat=$_POST[“alamat”];
$telepon=$_POST[“telepon”];
$kota=$_POST[“kota”];
$pekerjaan=$_POST[“pekerjaan”];

include”konek.php”;
$sql = “select * from member”;
$laksanakan = mysql_query($sql);

echo”<table width=500 border=2 cellspacing=2 cellpadding=0>”;
echo”<tr><td>member</td><td>pass</td><td>nama</td><td>alamat</td><td>telepon</td><td>kota</td><td>pekerjaan</td><td>Edit</td><td>Delete</td></tr>”;

while ($data = mysql_fetch_array($laksanakan)){
echo”<tr><td>$data[member]</td><td>$data[pass]</td><td>$data[nama]</td><td>$data[alamat]</td><td>$data[telepon]</td><td>$data[kota]</td><td>$data[pekerjaan]</td><td><a href=signup.php?id=$data[member]>Edit</td><td><a href=hapus.php?id=$data[member]>Delete</td></tr>”;
}
echo”</table>”;
?>





Syntax Login

9 06 2008

<?
session_start();
$user=$_POST[“user”];
$pass=$_POST[“pass”];
include ‘konek.php’;
$cekadm=mysql_query(“select * from admin where admin=’$user’ and pass=’$pass'”);
$cekmemb=mysql_query(“select * from member where member=’$user’ and pass=’$pass'”);
if ((mysql_num_rows($cekadm))==1){
session_register(‘user’);
header(“location:admin.php”);
}
elseif((mysql_num_rows($cekmemb))==1){
session_register(‘user’);
header(“location:member.php”);
}
else{
header(“location:gagallogin.php”);
}
?>





Syntax Delete

9 06 2008

<?
include”konek.php”;
$sql=”delete from member where member=’$data'”;
$laksanakan=mysql_query($sql);
if ($laksanakan){
header(“location:tampil.php”);
}else{
echo “data gagal dihapus”;
}
?>





Syntax Save

9 06 2008

<?
$member=$_POST[“member”];
$pass=$_POST[“pass”];
$nama=$_POST[“nama”];
$alamat=$_POST[“alamat”];
$telepon=$_POST[“telepon”];
$kota=$_POST[“kota”];
$pekerjaan=$_POST[“pekerjaan”];

include”konek.php”;
$sql=”insert into member(member,pass,nama,alamat,telepon,kota,pekerjaan) values (‘$member’,’$pass’,’$nama’,’$alamat’,’$telepon’,’$kota’,’$pekerjaan’)”;
$laksanakan = mysql_query($sql);

if ($laksanakan){
header(“location:index.php”);
}else{
echo “data tidak bisa disimpan”;
}
?>