简体   繁体   中英

Connection to oracle server for login.php

I am trying to connect to oracle server with is in the uni. I think it does connect however i cant select from table to check if the login credentials are same in order to login. I have tried other ways as well but this is the closest i got so far. Problem is in the oci_bin part thats where it is showing error but i dunno any other way to solve this.

<?php
session_start();

if(!isset($_POST['username']) || !isset($_POST['password'])) {
    header("Location: ../session.php");
}

putenv("ORACLE_SID=teaching");
if ($Connection = oci_connect("w4e09", "melih312")) {
    print "Connection OK \n";}

    if(isset($_SESSION['loggedin'])) header("Location: ../secret.php");

    $Statement = oci_parse($Connection, 'select *
                                    from Company
                                    where address = :un_bv
                                    and email = :pw_bv' );
    Oci_bind_by_name($s, ":un_bv", $_POST['username']);
    Oci_bind_by_name($s, ":pw_bv", $_POST['password']);
    oci_execute($s);
    $r = oci_fetch_array($s, OCI_ASSOC);
}
if ($r) {
    $_SESSION['loggedin']=TRUE; $_SESSION['username']="admin";
}
else {
    // No rows matched so login failed
    login_form('Login failed. Valid usernames/passwords ' .
               'are "chris/tiger" and "alison/red"');
}
header("Location: secret.php");
?>

oci_bind_by_name , oci_execute and oci_fetch_array have to use the resource returned by oci_parse . In your case, that would be the $Statement variable:

$Statement = oci_parse(
    $Connection,
    'select * from Company where address = :un_bv and email = :pw_bv'
);

oci_bind_by_name($Statement, ":un_bv", $_POST['username']);
oci_bind_by_name($Statement, ":pw_bv", $_POST['password']);

oci_execute($Statement);
$r = oci_fetch_array($Statement, OCI_ASSOC);

Take a look at the documentation:

http://php.net/manual/en/function.oci-connect.php

http://php.net/manual/en/function.oci-parse.php

Add some error checking:

// During development only
error_reporting(E_ALL);  // In PHP 5.3 use E_ALL|E_STRICT
ini_set('display_errors', 'On');

. . .

if ($Connection = oci_connect("w4e09", "melih312")) {
    print "Connection OK \n";}
else {
    $m = oci_error();
    trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
}

Similarly check errors after oci_execute() .

See "Handling PHP OCI8 Errors" on p 161 of Oracle's free book http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM