Published in: PHP
URL: http://wiki.splitbrain.org/mysimple.php
This simple script can be used to send any query to a MySQL database - useful if you need to quickly access a database without install a full blown manager like PHPMyAdmin.
<?php /** * Simple PHP MySQL Client * Copyright (c) 2007, Andreas Gohr <andi (at) splitbrain.org> * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * * Neither the name of Andreas Gohr nor the names of other contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // disable magic quotes } if(!$_POST['db_host']) $_POST['db_host'] = 'localhost'; ?> <html> <head> <title>MySimple</title> <style type="text/css"> body { font: 90% sans-serif; } table { font: 90% sans-serif; border-right: 1px solid #000; border-top: 1px solid #000; empty-cells: show; } td, th { border-left: 1px solid #000; border-bottom: 1px solid #000; padding: 0.2em 0.5em; } input, textarea, fieldset { border: 1px solid #333; } </style> </head> <body> <form action="" method="post"> <fieldset> <legend>Database Connection</legend> <label for="db_host">Host:</label> <label for="db_name">Database:</label> <label for="db_user">User:</label> <label for="db_pass">Password:</label> </fieldset> <fieldset> <legend>Query</legend> <textarea name="query" style="width: 98%" rows="20"><?php echo htmlspecialchars($_POST['query'])?></textarea><br /> <input type="submit" name="go" style="cursor: hand" /> (separate multiple queries with a semicolon at end of line) </fieldset> <?php // do the work if($_POST['go']){ $ok = true; echo '<fieldset><legend>Results</legend>'; // connect to db host if(!$link){ $ok = false; }else{ echo "<b>Connected to host</b><br />"; } // select database if($ok){ if($_POST['db_name']){ $ok = false; }else{ echo "<b>Database selected</b><br />"; } } } // run queries if($ok){ if($_POST['query']){ |\r|\n)/s",$_POST['query']); foreach($queries as $query){ echo '<hr >'; if(!$result){ }else{ if($result != 1){ $first = true; if($first){ echo "\t<tr>\n"; } echo "\t</tr>\n"; $first = false; } echo "\t<tr>\n"; foreach ($line as $col_value) { } echo "\t</tr>\n"; } echo "</table>\n"; } } } } } echo '</pre></fieldset>'; } ?> </form> </body> </html>
You need to login to post a comment.
