note 79458 deleted from ref.sqlite by felipe
| From: | felipe@php.net | Date: | Mon, 24 Dec 2007 01:49:21 +0000 |
| Subject: | note 79458 deleted from ref.sqlite by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133923@lists.php.net to get a copy of this message | ||
Note Submitter: alex_stef userof yahoo.com
Reason: 1
----
Simple sqliteadmin.php
<?php
if (!isset($_POST['database'])){
?><form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="post">
<p>
Database file:<input type="text" name="database" size=20 maxlength=20
value="">
</p>
<?php
} else
{ ($db = sqlite_open($_POST['database'])) or die('Cannot open the file');
echo '<p>You operate on "'.$_POST['database'].'"
database<br>';
// Now $db is the opened database
$exec=get_magic_quotes_gpc() ? stripslashes($_POST['exec']) : $_POST['exec'];
if ($exec !=''){echo 'Result-less
query:<br><pre>'.$exec.'</pre>';
sqlite_exec ($db,$exec,$err) or die(sqlite_error_string($err));}
$query=get_magic_quotes_gpc() ? stripslashes($_POST['query']) : $_POST['query'];
if ($query ==''){$query="select * from sqlite_master order by type,name";}
echo 'Query:<br><pre>'.$query.'</pre>';
$qh = sqlite_unbuffered_query ($db,$query);
$f=true;
while ($entry = sqlite_fetch_array($qh, SQLITE_ASSOC)){
if ($f){$keys=array_keys($entry);echo '<table><tr>';$f=false;
foreach ($keys as $key){echo '<th>'.$key;}} else
{echo '<tr>';foreach ($entry as $key => $val){echo '<td>'.$val;}}
}
echo '</table>';
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="post">
<p>Next Result-less query:<br>
<textarea name="exec" rows="10" cols="80"></textarea>
<p>Next Select query:<br>
<textarea name="query" rows="10" cols="80"></textarea>
<input type="hidden" name="database" value="<?php echo
$_POST['database']?>">
<input type="submit" value="Send">
<?php
}?>
You can experiment with the SQLite commands as explained in http://www.sqlite.org/lang.html. You may notice that
sqlite_unbuffered_query() will always process only the first query, although that one may contain
many nested queries.