<?php
// Once you have a valid DB object named $db...
$db->setFetchMode(DB_FETCHMODE_ORDERED);
$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28');
$row =& $res->fetchRow();
print_r($row);
echo 'Column a is ' . $row[0];
?>
<?php
// Once you have a valid DB object named $db...
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28');
$row =& $res->fetchRow();
print_r($row);
echo 'Column a is ' . $row['a'];
?>
<?php
// Once you have a valid DB object named $db...
$db->setFetchMode(DB_FETCHMODE_OBJECT);
$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28');
$row =& $res->fetchRow();
print_r($row);
echo 'Column a is ' . $row->a;
?>
Output:
stdClass Object
(
[a] => 28
[b] => hi
)
Column a is 28
<?php
// Once you have a valid DB object named $db...
$db->setFetchMode(DB_FETCHMODE_OBJECT, 'DB_row');
$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28');
$row =& $res->fetchRow();
print_r($row);
echo 'Column a is ' . $row->a;
?>
Output:
db_row Object
(
[a] => 28
[b] => hi
)
Column a is 28
<?php
// Once you have a valid DB object named $db...
class SomeResult {
function SomeResult($data) {
foreach ($data as $key => $value) {
$this->$key = $data[$key];
}
}
}
$db->setFetchMode(DB_FETCHMODE_OBJECT, 'SomeResult');
$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28');
$row =& $res->fetchRow();
print_r($row);
echo 'Column a is ' . $row->a;
?>
Output:
SomeResult Object
(
[a] => 28
[b] => hi
)
Column a is 28
<?php
// Once you have a valid DB object named $db...
class SomeResult {
public $row_data;
function __construct($data) {
$this->row_data = $data;
}
function __get($variable) {
return $this->row_data[$variable];
}
}
$db->setFetchMode(DB_FETCHMODE_OBJECT, 'SomeResult');
$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28');
$row =& $res->fetchRow();
print_r($row);
echo 'Column a is ' . $row->a;
?>
Output:
SomeResult Object
(
[a] => 28
[b] => hi
)
Column a is 28