RE: [PEAR] DB first time use
| From: | Herman Sinte Maartensdijk | Date: | Mon, 26 Apr 2004 09:58:09 +0000 |
| Subject: | RE: [PEAR] DB first time use | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-12121@lists.php.net to get a copy of this message | ||
I believe the default 'fetchmode' is DB_FETCHMODE_ORDERED, which gives you a numeric
array, instead of an associative, which explains why the Name is an undiefined index.
Set the fetchmode to DB_FETCHMODE_ASSOC
See http://pear.php.net/manual/en/package.database.db.db-common.setfetchmode.php
Herman
-----Original Message-----
From: Nunners [mailto:webmaster@jnsolutions.co.uk]
Sent: Monday, April 26, 2004 11:51
To: 'PEAR list'
Subject: [PEAR] DB first time use
Hi All,
I'm doing a project, and am trying to use DB for the first time.
I've got as far as the following:
<?php
require_once("DB.php");
$dsn = array(
'phptype' => 'mysql',
'username' => 'root',
'password' => 'password',
'hostspec' => 'localhost',
'database' => 'portal',
);
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);
$db =& DB::connect($dsn, $options);
if (DB::isError($db)) {
die($db->getMessage());
}
$sql = 'select * from agents';
$res =& $db->query($sql);
if (DB::isError($res)) {
die($res->getMessage());
}
echo $res->numRows(); // returns 1
while ($res->fetchInto($agent)) {
echo $agent['name'] . "\n"; //returns Undefined index: Name
}
?>
As you can see from my comments, it correctly returns the number of rows,
however doesn't recognize any indexes. I've installed the latest version
1.6.2....
Am I doing something really silly?
Cheers
James
--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php