PHP/MySQL,HTML,JavaScript,Java Programming examples. Free Software, Earn Money Online.
PHP: Getting List of Database & Tables in MySQL
Query1: Show Databases returns List of Databses in MySQl
Query2: Show Tables returns List of Tables in selected Database.
dbconnect.php
<?php
Class dbconnect
{
function __Construct()
{
$this->cn=mysql_connect("localhost","root");
}
function firequery($q)
{
$res=mysql_query($q);
return $res;
}
function __Destruct()
{
mysql_close( $this->cn);
}
function selectdb($name)
{
mysql_select_db($name);
}
}
?>
ListDatabase.php
<?php
try
{
require_once('dbconnect.php');//to make available database functions from dbconnect.php
$obj=new dbconnect();
$res=$obj->firequery('Show Databases');
echo '<h3>List of Databases in MySQL</h3>';
echo '<form name="frm" method="post"><select name="s1" multiple onchange=submit();>';
while($row=mysql_fetch_row($res))
{
echo "<option>$row[0]</option>";
}
echo '</select></form>';
if(isset($_POST['s1']))
{
$obj->selectdb($_POST['s1']);
$res=$obj->firequery('show tables');
echo "<h3>Tables in <i>".$_POST['s1']. "</i></h3>";
while($row=mysql_fetch_row($res))
{
echo "$row[0]<br/>";
}
}
}
catch(Exception $e)
{
echo 'OOPS!'.$e->getMessage();
}
?>
Subscribe to:
Post Comments (Atom)
I loved as much as you will receive carried out right here. The sketch is attractive, your authored subject matter stylish. nonetheless, you command get got an shakiness over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly very often inside case you shield this increase.
ReplyDeleteRemove Pending Friend Request Facebook : Increase chance of not getting block