tags:

views:

29

answers:

1

Greetings Overflowers,

What is wrong with this PHP code:

<?php
define("DB_FILE", "sqlite:database.sql");
define("QUERY", "INSERT INTO Log VALUES (123)");
define("TIME_OUT", "60000");

function track() {
 $db = new PDO(DB_FILE);
 $db->exec(QUERY);

 echo "OK!";
}

register_shutdown_function("track");

// sleep(TIME_OUT);
?>

Although "OK!" is printed when script is shutdown, nothing is really inserted into the database table. I tried calling track() directly and it did insert. Can not I do databases inside shutdown functions ?

Regards

+1  A: 

Hello,

First of all you should check if your query ran OK before outputting the OK! message. Use PDO::errorInfo to see what (if anything) went wrong.

Alin Purcaru
Might I add to also check that the PDO object was actually created / connection succeeded.
Fanis
Thanks! Actually, the path to the database file was the problem :)
geeko