Dear all, This time the code below work perfectly! <?php try { print "PDO test\n"; $dbh = new PDO('sqlite:db1.db'); $dbh->exec("drop table if exists tbl2"); $dbh->exec("create table tbl2 (one varchar(10),two varchar(10))"); $dbh->exec("insert into tbl2 values('test1a','test2a')"); $dbh->exec("insert into tbl2 values('test1b','test2b')"); $dbh->exec("insert into tbl2 values('test1c','test2c')"); $dbh->exec("insert into tbl2 values('test1d','test2d')"); $result=$dbh->query('select * from tbl2'); foreach($result as $row) { print "row=".$row['one'].",".$row['two']."\n"; } $dbh=NULL; print "Done\n"; } catch(PDOException $e) { print "Exception: ".$e->getMessage(); } ?>
I managed to find out why yesterday's code is not working: $result=$dbh->query("create table tbl2 (one varchar(10),two varchar(10));"); actually if I remove the "$result=", directly put as below: $dbh->query("create table tbl2 (one varchar(10),two varchar(10));"); Then it also works. So thank you so much everybody! James ----- Original Message ---- From: "Black, Michael (IS)" <michael.bla...@ngc.com> To: General Discussion of SQLite Database <sqlite-users@sqlite.org> Sent: Mon, 11 July, 2011 9:18:30 PM Subject: Re: [sqlite] Insert not working for sqlite3 If CREATE has no return why do I get a return? To be clear I'm using PHP 5.3.6 and it most definitely gets a return But I re-wrote this according to some PDO examples I found. This is a more complete example. You should be able to run this with a PHP command line -- forget the web interface until you get this working. If the database can't be opened you'll get an exception. If this doesn't work then open up the database with sqlite3 and .dump it. <?php try { print "PDO test\n"; $dbh = new PDO('sqlite:db1.db'); $dbh->exec("drop table if exists tbl2"); $dbh->exec("create table tbl2 (one varchar(10),two varchar(10))"); $dbh->exec("insert into tbl2 values('test1a','test2a')"); $dbh->exec("insert into tbl2 values('test1b','test2b')"); $dbh->exec("insert into tbl2 values('test1c','test2c')"); $dbh->exec("insert into tbl2 values('test1d','test2d')"); $result=$dbh->query('select * from tbl2'); foreach($result as $row) { print "row=".$row['one'].",".$row['two']."\n"; } $dbh=NULL; print "Done\n"; } catch(PDOException $e) { print "Exception: ".$e->getMessage(); } ?> This displays this output D:\SQLite>php -e <test2.php PDO test row=test1a,test2a row=test1b,test2b row=test1c,test2c row=test1d,test2d Done Plus...check your phpinfo() for the sqlite3 entries and show them to us. The should look like this: SQLite3 support => enabled SQLite3 module version => 0.7-dev SQLite Library => 3.7.4 Michael D. Black Senior Scientist NG Information Systems Advanced Analytics Directorate ________________________________ From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Stephan Beal [sgb...@googlemail.com] Sent: Monday, July 11, 2011 6:10 AM To: General Discussion of SQLite Database Subject: EXT :Re: [sqlite] Insert not working for sqlite3 On Mon, Jul 11, 2011 at 2:41 AM, James_21th <james_2...@yahoo.com> wrote: > $result=$dbh->query("create table tbl2 (one varchar(10),two > varchar(10));"); > A CREATE statement has no results. In PDO, only SELECT (and similar) return a result, if i'm not mistaken. -- ----- stephan beal http://wanderinghorse.net/home/stephan/ _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users