2

I am invoking a PHP script from and Android client. Here is the PHP script

 <?php
//$user = $_GET['username'];
//$timestamp = $_GET['timestamp'];
//$latitude = $_GET['latitude'];
//$longtitude = $_GET['longtitude'];
//$filename = $_GET['filename'];

$user = "test";
$timestamp = 100;
$latitude = 10;
$longtitude = 10;
$filename = "test.jpg";

$dbname = "sqlite:/".dirname(__FILE__)."/terrapin";
$handle = new PDO($dbname);
if (!$handle) die ($error);

error_log("before exec",0);
$insert = "INSERT INTO information VALUES(NULL,'$user','$latitude','$longtitude','$timestamp','$filename')";
$handle->exec($insert);
error_log("after exec",0);
$handle = null;

$total = $user."\n".$timestamp."\n".$latitude."\n".$longtitude;
$name = "dumpp.txt";
$fh = fopen($name, 'w');
fwrite($fh,$total);
fclose($fh);
?>

The problem is, when I run the script from the command line, it works fine and inserts into the db. But when I remove the comments and get the values from the GET request and invoke the script from the client, nothing gets inserted into the db. There is nothing in the error, however both the error_log statements get printed. Any idea why this is happening?

1
  • This started working fine when I did this: $db = new SQLite3("terrapin"); $db->exec($insert); Commented Nov 2, 2011 at 8:49

3 Answers 3

1

I think you may have just hit the classic sqlite "Gotcha".

If the file you specify on the open statement does not exists sqllite will quietly create a new empty database. This new database will not have the tables your application expects defined inside.

Have a look in your application directories for an empty sqlite database created in an unexpected location.

Sign up to request clarification or add additional context in comments.

Comments

0

you should check it by print_r().

echo "<pre>";print_r($_GET);echo "</pre>";

if data is coming then you should check your query...

in short, you need to debug for your answer.

Comments

0

Unless you have constrains in your table something should be inserted, wheter it exists in $_GET or not.

Is the SQLite database file is writable (by Apache/PHP), as well as the dirname(__FILE__) folder?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.