I'm trying to select a specific ID that is auto-generated by the oracle database for a specific session user(from log in and its working fine). I'm using MDB2 to achieve this. I am following the pear: MDB2 manual and did the codes the way it is but I'm getting an error. Please help.
I have used the fetchOne(MDB2_FETCHMODE_ASSOC) to achieve this from the reading manual and its giving an error
<?php
session_start();
$user = $_SESSION['user'];
echo "Welcome:\t".$user;
require_once 'MDB2.php';//pear MDB2
include "conn.php";
$do= "SELECT customer_id FROM customer WHERE username=".$user;
$query= $db->query($do);
if($one=$query->fetchOne(MDB2_FETCHMODE_ASSOC)){
$id= $one['customer_id'];
echo ($id);
}
?>
The number 2 should be printed out but instead there this error: Fatal error: Call to undefined method MDB2_Error::fetchOne() in C:\wamp64\www\grahams\home.php on line 12
Try using below code.
<?php
session_start();
$user = $_SESSION['user'];
echo "Welcome:\t".$user;
require_once 'MDB2.php';//pear MDB2
include "conn.php";
$do= "SELECT customer_id FROM customer WHERE username=".$user;
$id = queryOne($do);
if(isset($id))
{
echo $id;
}
?>
Since queryOne() query the database and select the column from the given query.
Edit: in conn.php check whether the connection is okay. following is the example code.
<?php
$dsn = array(
'phptype' => 'oci8',
'hostspec' => null,
'username' => 'oci_username',
'password' => 'oci_password',
);
// Establish database connection
$db = MDB2::connect($dsn);
// Check if the connection was established successfully
if (PEAR::isError($db)) {
die('Could not create database connection. "'.$db->getMessage().'"');
}
?>