Why can I use SELECT but not INSERT on a SQLite database in PHP?

aloul84

New Member
I am able to retrieve information from a SQLite database in PHP, but not write to it. For example, this code works perfectly fine:\[code\]$db = new PDO("sqlite:foo.db");$rowCount = $db->query("SELECT COUNT(*) FROM tblname;")->fetchColumn(0);echo $rowCount; // works as it should\[/code\]However, the following snippet results in an, 'unable to open database file' error:\[code\]$db = new PDO("sqlite:foo.db");$db->exec("INSERT INTO tblname VALUES(NULL, 'val1', 'val2');") or die(print_r($db->errorInfo(), true));\[/code\]When I perform the above INSERT from the command line rather than in PHP, I get the expected results (a new row in tblname):\[code\]$ sqlite3 foo.dbsqlite> INSERT INTO tblname VALUES(NULL, 'val1', 'val2');\[/code\]This is my first time using PDOs (or SQLite for that matter) so any help would be greatly appreciated.
 
Back
Top