vendredi 27 mars 2015

How to determine data types from query results in SQLite with php

I have created a table and inserted some data in SQLite with php. I need to run some query and put the query results in .csv file as well as put the associated data types in .cfg file. For example:


Table1


col1 TEXT, col2 INTEGER, col3 TEXT, col4 INTEGER ...



// sample queries:
$query1 = 'SELECT * FROM Table1';
$query2 = 'SELECT col1, col2 FROM Table1';
$query3 = 'SELECT col1, col2 AS 'anothercolname' FROM Table1';

$stat = $dbh->query($query*);
$result = $stat->fetchAll(PDO::FETCH_ASSOC);

$handle=fopen('path/to/result.csv','w');
foreach($result as $r)
{
fputcsv($handle,$r);
}
fclose($handle);
// codes needed to write data types to .cfg file
....

Aucun commentaire:

Enregistrer un commentaire