In article <qu2dnXh3ydsQTvLVnZ2dnUVZ_rjinZ2d@comcast.com>,
Chuck Anderson <websiteaddress@seemy.sigwrote:
Quote:
I figured out how to get at my firefox sqlite files. I need to use the
PDO functions as they are in sqlite 3 format.
>
Anyway .... what I want to do now is the equivalent of SHOW COLUMNS (in
MySQL), so that I can open any table and see it's structure. I have yet
to find a way. Does anyone know how to use PDO SQLite to display a
tables columns?
Try this code:
<?
echo "\nDatabase dumper V001\n\n";
echo "Enter database name: ";
$database = trim (fgets (STDIN), "\n ");
echo "\n";
if (file_exists($database)==false)
{
echo "Error - database does not exist\n\n";
echo "Abnormal termination\n\n";
exit ();
}
echo "Enter table name: ";
$table = trim (fgets (STDIN), "\n ");
echo "\n";
$dbh = new PDO ("sqlite:" . $database);
$resq = $dbh->query ("PRAGMA table_info(" . $table . ")");
$cols = $resq->fetchAll (PDO::FETCH_BOTH);
$num = count ($cols);
echo "Number of columns = " . $num . "\n\n";
for ($i=0; $i<$num; $i++)
{
$numfld = count ($cols[$i]);
for ($j=0; $j<$numfld; $j++)
{
echo $cols[$i][$j] . " ";
}
echo "\n";
}
?>