I need to simply insert a new row (and also be able to delete rows) in an SQLite3 DB file. I'm able to successfully list contents of the table, but when I try to INSERT new rows into the table it doesn't seem to work. After trying several methods, this is the code I've come up with:
Code: Select all
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
try {
/*** Open db connection or file ***/
$dbhandle = new PDO('sqlite:globalbans.db');
echo 'Connected to database<br />';
/*** Add new ban for setGUID ***/
$count = $dbhandle->exec("INSERT INTO BANS VALUES ('aabbccddeeff11223344556677889900', 'TestReason', '11052011')");
/*** Echo number of rows affected ***/
echo 'Successfully added ' . $count . ' bans to the list';
/*** Close the db ***/
$dbhandle = null;
echo 'Closed database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>I'm running this on:
Debian 6
Apache 2
PHP 5.3.3-7+squeeze3
SQLite Library 3.7.3