Get all records From whole database tables with a single query using php.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cms";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
if (!mysql_connect('localhost', 'root', '')) {
    echo 'Could not connect to mysql';
    exit;
}
$sql = "SHOW TABLES FROM $dbname";
$dbresult = mysql_query($sql);
while ($row = mysql_fetch_row($dbresult)) {
foreach($row as $r){
$sql = "SELECT * FROM ".$r;
echo ' table ====>'.$r.'<br>';
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
print_r($row);  
echo mysql_insert_id();
}
echo '<br/><br/><br/>';
} else {
    echo "<H1>0 results</H1>";
}
 }}
?>

Share this

Related Posts

Previous
Next Post »