vendredi 20 février 2015

PHP + SQLite duplicate inserts

Every insert I do happens twice. I thought the page might be getting hit twice so I also added a counter file that would increment on each load. The page is only getting hit once, yet each insert is inserted twice.



<?
$x = intval(file_get_contents("./count.x"));
header("Content-type: text/plain");
$db = new SQLite3("/var/www/images/cache.db");

$statement = $db->prepare('insert into `imgCache` (name,type,data) values("test7","bmp","argh);');
$result = $statement->execute();


while ($row = $result->fetchArray(SQLITE3_ASSOC))
{
print_r($row);
}


$x++;
file_put_contents("./count.x",$x);

?>


Prior to running this script there is no entry for "test7" in the database, and the contents of count.x is "0".


When I run this script, the following happens



  1. count.x contains the text "1"

  2. there are TWO entries for test7 in the database now.


Aucun commentaire:

Enregistrer un commentaire