Page 1 of 1

Fetching data from SQLite

Posted: Tue Nov 22, 2011 4:24 pm
by ArkaneArkade
Hey guys,
I'm trying to write a script to deal with some automation features of a media player. I need to edit the data in the database, which is stored in an SQLite3 database.

I've tried using a XAMPP installation to access the file, but that failed, so now I have a script using PDO to access it. unfortunatly I don't really understand anything else to do with it.

Code: Select all

<?php
$dbh = new PDO('sqlite:Videos34.db');
foreach ($dbh->query('SELECT idFile, c07 FROM movie') as $row)
{
	$UID = $row[0];
	$id2 = $row[1];
}
I've run that and can access it, but the information is stored in a myriad of different tables, and I need to take data from loads of them. I know I'm going to need multiple queries, but I don't know how to actually get the data.
For each query there will be only a single row as a result, as they will all be searched via a unique id. I tried just accessing, but get "Catchable fatal error: Object of class PDOStatement could not be converted to string".
All I need help with, is if anybody can tell me how to retieve the data. At most I want 2 fields from each table, but will need to store the answers as string variables. How can I convert the PDOStatement to an array?

Re: Fetching data from SQLite

Posted: Tue Nov 22, 2011 7:02 pm
by Celauran
ArkaneArkade wrote:How can I convert the PDOStatement to an array?

Code: Select all

$query = "SELECT foo, bar
          FROM tablename
          WHERE whatever";
$result = $pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);