[英]I am doing this code in php while selecting any database it only display the number of tables not the names of all tables of the selected database
[英]When selecting any database it only displays the number of tables not the names of all tables of the selected database
<?php
session_start();
include 'dbconnect.php';
$q=$_GET['q'];
echo $field= "Tables_in_".$q;
$sql = "SHOW TABLES FROM $q";
$result= mysqli_query($conn,$sql);
$new= array();
$i=0;
while ($row=mysqli_fetch_row($result)){
echo $row['Tables_in_mysql'];
$new[$i]=$row;
$i++;
}
echo $num=count($new);
?>
這是我的代碼,請幫助我在 php 中打印所選數據庫表的所有名稱其中表的數量,但我想顯示表的名稱
請查看您的mysqli
調用中是否存在任何錯誤。
這是工作代碼。
$conn = new mysqli("localhost", "root", "");
$dbname = 'db_name';
$sql = "SHOW TABLES FROM $dbname";
$result = mysqli_query($conn,$sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysqli_error();
exit;
}
while ($row = mysqli_fetch_row($result)) {
echo "Table: {$row[0]}\n";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.