note 39882 added to ref.sqlite
| From: | jlsalinas at spamsucks dot gmx dot net | Date: | Fri, 13 Feb 2004 23:22:51 +0000 |
| Subject: | note 39882 added to ref.sqlite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65123@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/ref.sqlite.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39882
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39882&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39882&report=yes
Search -- http://master.php.net/manage/user-notes.php