PDO and SQLite3 problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jpratt
Forum Newbie
Posts: 1
Joined: Tue Aug 07, 2007 8:36 pm

PDO and SQLite3 problem

Post by jpratt »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This is my connection string:

Code: Select all

<?php
//database connection
try {
    $db = new PDO('sqlite:drive.sqlite3'); //sqlite 3
}
catch (PDOException $error) {
   print "error: " . $error->getMessage() . "<br/>";
   die();
}
?>
And this is my SELECT on my page:

Code: Select all

require_once('db/config.php');

$sql = "SELECT * FROM user";
$prepstatement = $db->prepare($sql);
$prepstatement->execute();

while($row = $prepstatement->fetch()) {
    $id = $row["userID"];
}
if (!(isset($id))) {
header('newuser.php');
}
I am new to the whole PDO thing and dont understand why it is thowing this error:

Fatal error: Call to a member function execute() on a non-object in L:\PortableWebAp3.5.1\Program\www\localhost\index.php on line 6

any ideas?? Thanks.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

It means that..

Code: Select all

$db->prepare($sql);
is not returning an object.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: PDO and SQLite3 problem

Post by volka »

please try

Code: Select all

<?php
//database connection
try {
    $db = new PDO('sqlite:drive.sqlite3'); //sqlite 3
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $error) {
   print "error: " . $error->getMessage() . "<br/>";
   die();
}
?>
Post Reply