note 107192 deleted from function.sqlite-query by cmb
| From: | cmb@php.net | Date: | Mon, 02 Nov 2020 15:02:50 +0000 |
| Subject: | note 107192 deleted from function.sqlite-query by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215752@lists.php.net to get a copy of this message | ||
Note Submitter: glenn at byte-consult dot be
----
Not a lot of examples on using the oo style of using sqlite files. Maybe this helps someone trying
to figure out all the names of the tables inside an sqlite file.
<?php
/* Just extend the class, add our method */
class MySQLiteDatabase extends SQLiteDatabase {
/* A neat way to see which tables are inside a valid sqlite file */
public function getTables() {
$tables=array();
$q = $this->query(sprintf("SELECT name FROM sqlite_master WHERE type='table'
ORDER BY name"));
$result = $q->fetchAll();
foreach($result as $tot_table) {
$tables[]=$tot_table['name'];
}
return($tables);
}
}
/* a sqlite file */
$database="BLAHBLAH.sqlite";
if (file_exists($database)) {
$db = new MySQLiteDatabase($database, 0666, $err);
if ($err) {
trigger_error($err);
} else {
print_r($db->getTables());
}
}
/* this sqlite db had 2 tables:
Array
(
[0] => Account
[1] => Device
)
*/
?>