note 80874 deleted from function.sqlite-query by cmb
| From: | cmb@php.net | Date: | Mon, 02 Nov 2020 15:02:48 +0000 |
| Subject: | note 80874 deleted from function.sqlite-query by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215751@lists.php.net to get a copy of this message | ||
Note Submitter: helmakil at gmail dot com
----
I suppose this could be useful for users attempting to use a sqlite database for the first time.
<?php
$database = new SQLiteDatabase($yourfile, 0666, $error);
if (!$database) {
$error = (file_exists($yourfile)) ? "Impossible to open, check permissions" :
"Impossible to create, check permissions";
die($error);
}
$query = $database->query("SELECT name FROM sqlite_master WHERE
type='table'", SQLITE_ASSOC, $query_error); #Lists all tables
if ($query_error)
die("Error: $query_error"); #This means that most probably we catch a syntax error
if (!$query)
die("Impossible to execute query.") #As reported above, this means that the db owner is
different from the web server's one, but we did not commit any syntax mistake.
print $query->numRows();
while ($row = $query->fetch())
print($row['name']."\n");
?>
i suppose that the example above is also useful because it will list all the tables created, giving
also comprehension of what appens when managing a sqlite database in OO mode.