[英]how to select specific field from a database using mdb2 php?
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). 我正在尝试选择由oracle数据库为特定会话用户自动生成的特定ID(从登录及其正常工作)。 I'm using MDB2 to achieve this.
我正在使用MDB2来实现这一点。 I am following the pear: MDB2 manual and did the codes the way it is but I'm getting an error.
我关注的是梨子:MDB2手册,按原样进行了编码,但是出现错误。 Please help.
请帮忙。
I have used the fetchOne(MDB2_FETCHMODE_ASSOC) to achieve this from the reading manual and its giving an error 我已经使用fetchOne(MDB2_FETCHMODE_ASSOC)从阅读手册中实现了这一点,并且给出了错误
<?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 应该打印出数字2,但是出现以下错误:致命错误:在第12行的C:\\ wamp64 \\ www \\ grahams \\ home.php中调用未定义的方法MDB2_Error :: fetchOne()
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. 由于queryOne()查询数据库并从给定查询中选择列。
Edit: in conn.php check whether the connection is okay. 编辑:在conn.php中检查连接是否正常。 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().'"');
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.