note 46747 deleted from ref.sqlite by cmb
| From: | cmb@php.net | Date: | Mon, 02 Nov 2020 14:56:59 +0000 |
| Subject: | note 46747 deleted from ref.sqlite by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215708@lists.php.net to get a copy of this message | ||
Note Submitter: artooro at gmail dot com
----
If you need to check if a table exists, you can use a function like this:
<?php
//Returns TRUE if table exists and FALSE otherwise
// $mytable = table you want to check for
function sqlite_table_exists($mytable) {
$db = sqlite_open('mydb.sqlite', 0666, $sqliteerror);
$query = sqlite_query($db, "SELECT name FROM sqlite_master WHERE
type='table'");
$tables = sqlite_fetch_array($query);
if ($tables != '') {
foreach ($tables as $table) {
if ($table == $mytable) {
return("TRUE");
}
else {
return("FALSE");
}
}
}
else {
return("FALSE");
}
}
?>
A function like this could be used to create the table if it's not already created, etc.