PEAR DB
| From: | janet at valade dot com | Date: | Mon, 26 May 2003 03:31:18 +0000 |
| Subject: | PEAR DB | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-28029@lists.php.net to get a copy of this message | ||
Can anyone tell me why the code below doesn't work? I have looked at examples
and read documentation until my eyes are crossed, but I swear that mine is
the same as theirs. I don't get any errors. There just isn't any data in
$row. Or at least I get empty output when I echo row. var_dump() says $row is
NULL.
If I modify this same script, just changing the DB lines to lines with mysql
functions, I get the data I expect from the database. But with the DB
statements, I get nothing. . So, does anyone see what I have wrong?
$user = "root";
$passwd = "";
$dbname = "Test";
$dbtype = "mysql";
$dsn = "$dbtype://$user:$passwd@$host/$dbname";
echo "dsn=$dsn<br>";
$db = DB::connect($dsn) or die("connect died");
if(DB::isError($db))
{
die ("connect died");
}
$sql = "SELECT * from producttype";
$result = $db->query($sql) or die("query died");
if(DB::iserror($result))
{
die ("query died");
}
$row = $db->fetchRow(DB_FETCHMODE_ASSOC);
if(DB::iserror($row))
{
die("bad row");
}
echo "row={$row['PType']}<br>";
echo "<pre>";
var_dump($row);
echo "</pre>";
?>
Thanks for any suggestions,
Janet