note 107192 added to function.sqlite-query

From: Date: Fri, 13 Jan 2012 13:16:55 +0000
Subject: note 107192 added to function.sqlite-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-185632@lists.php.net to get a copy of this message
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 ) */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 81.165.31.179 ---- Manual Page -- http://www.php.net/manual/en/function.sqlite-query.php Edit -- https://master.php.net/note/edit/107192 Del: integrated -- https://master.php.net/note/delete/107192/integrated Del: useless -- https://master.php.net/note/delete/107192/useless Del: bad code -- https://master.php.net/note/delete/107192/bad+code Del: spam -- https://master.php.net/note/delete/107192/spam Del: non-english -- https://master.php.net/note/delete/107192/non-english Del: in docs -- https://master.php.net/note/delete/107192/in+docs Del: other reasons-- https://master.php.net/note/delete/107192 Reject -- https://master.php.net/note/reject/107192 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185632) next »