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.
code:
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
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')");
Don't ye forget that yer directory as well as yer database be needin' write permissions, beist ye usin sqlite in Unix or Linux. Arrrr...
After the query [example: $query = $db->query("INSERT INTO table (column1, column2...) VALUES ('$value1','$value2'...)"
)] add the clause "OR DIE" with the function last error code of sqlite3 [example: $db-> LastErrorCode());
]. This way you get the error code if it exists.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.