Hi everyone, I've never fooled with sqlite before and I'm trying to do a
simple query on an sqlite db, but I don't seem to be doing anything
correct. I can't figure out how to just simply open a db file in the
directory and query it and echo back the contents. Here's some code I've
been messing with trying to accomplish this but I get a blank screen.
places.sqlite is mozilla's bookmarks db and I was trying to read this
db, but so far I've been unsuccessful.
sqlite ver: 2.8.17
PHP version: PHP 5.3.3-1ubuntu9.6 with Suhosin-Patch
php5-sqlite: 5.3.3-1ubuntu9.6
try
{
//create or open the database
$database = new SQLiteDatabase('places.sqlite', 0666, $error);
}
catch(Exception $e)
{
die($error);
}
$query = "SELECT * FROM moz_bookmarks";
if($result = $database->query($query, SQLITE_BOTH, $error))
{
while($row = $result->fetch())
{
echo ("ID: {$row['id']} <br />" );
}
}
else
{
die($error);
}
But if I use this code:
try
{
/*** connect to SQLite database ***/
$dbh = new PDO("sqlite:places.sqlite");
echo "Handle has been created ...... <br><br>";
}
catch(PDOException $e)
{
echo $e->getMessage();
echo "<br><br>Database -- NOT -- loaded successfully .. ";
die( "<br><br>Query Closed !!! $error");
}
echo "Database loaded successfully ....";
I get the expected output, but can't figure out how to change the above
script to echo the contents of the DB. I just get the two messages and
that's it.
--
Thanks,
David M.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php