Cristina Cristina - 8 months ago 99
PHP Question

Can't add rows in SQLite3 with PHP, no error message displayed

I'm using PHP 5.3.19 and SQLite3 and I can't seem to add any rows to my table using PHP, and I don't get any error messages either. I do manage to do a select, but the INSERTS are not working.


try {
$dbh = new PDO("sqlite:database.db");
$dbh->exec("INSERT INTO TABLE_NAME (COL1, COL2, COL3) VALUES (null, $var1, $var2)");
echo "Row added";
catch(PDOException $e) {
echo $e->getMessage();
echo "<br><br>Database <b>NOT</b> loaded successfully. ";
die( "<br><br>Query Closed! $error");

this executes without any error messages, but the entry is not saved.

The directory is owned by webservd and is writable by webservd, so I really don't know what the problem is. When I run a PHP script via CLI, it doesn't do anything either, But if I try to enter the rows manually, it does work.

I checked the other posts about PHP and SQLite3, especially Unable to write to a chmod 777 database file on SQlite3 via php 5.3.0 , but couldn't find an answer.

Am I missing anything?

Thanks in advance for your help

Answer Source

I think you missed something; If your col2 and col3 is a string it should look something like:

$dbh->exec("INSERT INTO TABLE_NAME (COL1, COL2, COL3) VALUES (null, '$var1', '$var2')");

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download