Saturday 27 June 2015

PHP: Script to show all tables in a MySQL schema

<?php
//open database connection
$mysqli = new mysqli(<host>,<username>,<password>,<schema>);
 
//Display error message
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
 
$sql="SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = <schema name>";
$result=$mysqli->query($sql);
while ( $tables = $result->fetch_assoc())
{
echo "<br>".$tables['TABLE_NAME'];
}
// Free memory by clearing result
$result->free();
 
// close connection
$mysqli->close(); 
?>

0 comments:

Post a Comment