Thursday, July 14, 2011

php sqlite3 queries.

Getting sqlite into php is easy as Here is an example query. Of course im forced to use sqlite in the first place because im running an iphone as a web server.

try 
{
  $db = new PDO("sqlite:data.sqlite");
}
catch(PDOException $e)
{
  echo $e->getMessage();
  echo "<br><br>Database -- NOT -- loaded successfully .. ";
  die( "<br><br>Query Closed !!! $error");
}

#away with ye hackers..
$bbox = sqlite_escape_string($_GET['b']);
$bounds = split(" ", $bbox);
if ( count($bounds) != 4) { die("[]"); } 

$sql  = $db->prepare("SELECT * FROM readings WHERE lat >= ? AND long >= ? AND lat <= ? AND long <= ? LIMIT 1000");
if (! $sql->execute($bounds)) { die("[]"); } 
$query = $sql->fetchAll(PDO::FETCH_ASSOC); 

$decimated = decimate($query, $bounds);
jsonOutput($decimated);

No comments:

Post a Comment