gpt4 book ai didi

html - 连接到服务器,没有获取任何可视表

转载 作者:行者123 更新时间:2023-11-30 00:16:34 25 4
gpt4 key购买 nike

我正在从服务器请求中执行一个简单的获取表。但是当在我的本地机器上尝试时,我什么也没看到。我已经检查本地 MySQL 服务器是否正常运行,并且我提供的凭据应该正确。我没有收到任何错误,但正如我所说,我看不到数据库中的任何内容,但我可以看到页面上的其他元素。我很感谢我能得到的所有帮助,我对 MySQL 方面还很陌生。

这是我的代码:

     <html>
<style>
table.db-table { border-right:1px solid #ccc; border-bottom:1px solid #ccc; }
table.db-table th { background:#eee; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc; }
table.db-table td { padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc; }
</style>
</html>


<script>
$connection = mysql_connect('localhost','user','password');
mysql_select_db('my_db',$connection);

/* show tables */
$result = mysql_query('SHOW TABLES',$connection) or die('cannot show tables');
while($tableName = mysql_fetch_row($result)) {

$table = $tableName[0];

echo '<h3>',$table,'</h3>';
$result2 = mysql_query('SHOW COLUMNS FROM '.$table) or die('cannot show columns from '.$table);
if(mysql_num_rows($result2)) {
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo '<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default<th>Extra</th></tr>';
while($row2 = mysql_fetch_row($result2)) {
echo '<tr>';
foreach($row2 as $key=>$value) {
echo '<td>',$value,'</td>';
}
echo '</tr>';
}
echo '</table><br />';
}
}
</script>

最佳答案

我对此持怀疑态度,但我怀疑您没有看到任何返回的数据,因为“SHOW TABLES”和“SHOW COLUMNS”等命令不是实际的查询。它们是 MySQL 内部命令,因此我怀疑它们是否会由 mysql_query 执行。

您需要使用数据字典表,对于 MySQL 来说是 INFORMATION_SCHEMA数据库。所以你的第一个查询是:

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'my_db'

您的后续查询将是:

SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'my_db'
AND table_name = [table_name]

关于html - 连接到服务器,没有获取任何可视表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23610893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com