Kamis, 16 Mei 2013

Koneksi PHP - Oracle

buat file oraconn.php
<?php
$username = "xfun";
$password = "xfun123";
$dbname = "localhost/XE";
$c = oci_connect($username, $password, $dbname);
?>

lalu buat login.php
<?php
include("oraconn.php");
$submit = $_POST['btnSubmit'];
if (isset($submit))
    {
    $username = $_POST['username'];
    $pwd = $_POST['pwd'];
    $sql="select * from pegawai where username = '".$username."' and password = '".$pwd."'";
    $hasil= OCIParse($c, $sql);
    ociexecute($hasil);
    $tmpcount = OCIFetch($hasil);
        if($tmpcount==1)
            if($username<>admin and $password<>admin123)
            {
            session_start();
            $_SESSION['username'] = $username;
            $_SESSION['password'] = $password;
            setcookie("nama", $username);
            header("Location: utama.php");
            }
            else
            {
            session_start();
            $_SESSION['username'] = $username;
            $_SESSION['password'] = $password;
            setcookie("nama", $username);
            header("Location: admin.php");
            }
            else
            {
            header("Location: index.html");
            }
    }
?>