I getting connection and parse error when run this on the website to connect to my university Oracle. When you enter merchant ID and password it display connection or parse error. When you hit refreshed multiple time it will switch back between these two error. On the issue of connection error, I beleive my code is right because I have a connection test script on the website too that show the current date when succesfully connected to Oracle. I just copy the connection part from dbtest.php to merchant_auth.php, but merchant_auth.php show connection error even though the connection code is copy and paste from dbtest.php.
I use oci_bind_by_name to parse my query, it there any syntax that would cause it show parse error. I don't if I use the right fetch statement. I want to test if there is one tuple on the query showing there is match on username/password field on the database.
Also on oci_error, how do you properly write it. When it the shows, it only show the string part and not $error["message"] like ociparse error:
This is script is found on this url http://andradite.njit.edu/~xl8/login2.php Enter dave for Merchant ID and 123njit for password. These two field are on the oracle database when I check.
For some strange reason, it show me a connection error even though I copy the connection code from dbtest.php which is on URL http://andradite.njit.edu/~xl8/dbtest.php which successully connected to Oracle. You can check to URL to test it out.
Here is the script that show me error
<?php
include ("header.php");
// Set Oracle Enviroment
PutEnv("ORACLE_SID=course");
PutEnv("ORACLE_HOME=/afs/cad/solaris/oraclient10.2");
PutEnv("LD_LIBRARY_PATH=/afs/cad/solaris/oraclient10.2/lib");
// Connect to Oracle
$conn = ocilogon("user", "pass", "course");
if ($conn)
{
$error = oci_error();
printf("There was an error connecting. Error was: %s", $error["message"]);
die();
}
$name = $_POST['user'];
$pass = $_POST['pass'];
$stmt = @oci_parse($conn, "SELECT COUNT(*) FROM MERCHANT WHERE LOGIN = :name AND M_PASS = :pass");
if (!$stmt)
{
$error = oci_error($conn);
printf("ociparse error: %s", $error["message"]);
die();
}
// bind the input and output variable
oci_bind_by_name($stmt, ':name', $name, -1);
oci_bind_by_name($stmt, ':pass', $pass, -1);
$r = oci_execute($stmt);
if ($r)
{
$error = oci_error($stmt);
printf("ociparse error: %s", $error["message"]);
die();
}
// if there is a match with the merchant username and password
if (oci_fetch($stmt))
{
print "Merchant login is valid";
}
else
{
print "Merchant login is not in the database";
}
OCIFreestatement($stmt);
OCILogoff($conn);
?>
</body>
</html>
And here is dbtest.php which I copy and paste from
<?php
// Set Oracle Environment
PutEnv("ORACLE_SID=course");
PutEnv("ORACLE_HOME=/afs/cad/solaris/oraclient10.2");
PutEnv("LD_LIBRARY_PATH=/afs/cad/solaris/oraclient10.2/lib");
// Connect to Oracle
if ($conn = OCILogon("user", "pass",
" course")) {
echo "<CENTER><FONT SIZE=+4>Successfully connected to
Oracle.</FONT></CENTER>";
} else {
$err = OCIError();
echo "Oracle Connect Error " . $err["message"];
die();
}
// Select Data...
$s = OCIParse($conn, "select sysdate from dual");
OCIExecute($s, OCI_DEFAULT);
//Print data...
while (OCIFetch($s)) {
echo "<CENTER><FONT SIZE=+3>Oracle thinks today's date is
--" . ociresult($s, "SYSDATE") .
"</FONT></CENTER>\n";
}
// Close the connection
OCILogoff($conn);
php?>