Posts tagged ‘PDO’

14/11/2010

PDO/SQLite connection

I have been working for a while on a project involving running a PHP web application on on an ARM linux mini PC. There was an existing application on the PC whose SQLite database I needed to manipulate, to feed new values into the program from a web interface. The hardest thing by far was cross-compiling PHP to run in the ARM environment to include --enable-pdo --with-pdo-sqlite, but that would take too long to go into here.

I was able to collect and display data from the SQLite database using the following PHP code:

$connect = new PDO("sqlite:/path/to/sqlite.db");

$sql = "SELECT * FROM sqlite_table";

foreach ($connect->query($sql) as $info)
{
$val1=$info['val1'];

$val2=$info['val2'];
}

echo "$val1";

Advertisements
Tags: , , ,