note 39882 rejected from ref.sqlite by cmb

From: Date: Mon, 02 Nov 2020 14:56:43 +0000
Subject: note 39882 rejected from ref.sqlite by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215701@lists.php.net to get a copy of this message
Note Submitter: jlsalinas at spamsucks dot gmx dot net ---- For those looking for a function similar to mysql_list_tables, here you have: if (! function_exists ('sqlite_list_tables')) { function sqlite_list_tables (&$dblink) { $tables = array (); $sql = "SELECT name FROM sqlite_master WHERE (type = 'table')"; if ($res = sqlite_query ($dblink, $sql)) { while (sqlite_has_more($res)) { $tables[] = sqlite_fetch_single($res); } } return $tables; } } And a related funtion, to test if a given table exists: if (! function_exists ('sqlite_table_exists')) { function sqlite_table_exists (&$dblink, $table) { $sql = "SELECT count(name) FROM sqlite_master WHERE ((type = 'table') and (name = '$table'))"; if ($res = sqlite_query ($dblink, $sql)) { return sqlite_fetch_single($res) > 0; } else { return false; // or throw exception } } } Of course it would be preferable to have these functions included in the library, to avoid potential changes internal to SQLite; but we'll have to stick to this method until then.

« previous php.notes (#215701) next »