PHP选择SQL查看无输出 [英] PHP Select SQL view no output
本文介绍了PHP选择SQL查看无输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个从SQL数据库中提取视图的php文件.有人可以让我知道为什么这不起作用吗?似乎正在超时.我也没有出现连接错误.预先谢谢你.
I creating a php file that pulls a view from an SQL database. Can someone let me know why this isn't working? It seems to be timing out. I am not getting a connection error, either. Thank you in advance.
<?php
require ('mysqli_connect.php');
$sql = "SELECT * FROM testview ;";
$result = mysqli_query($dbc,$sql);
// Check connection if ($dbc->connect_error) {
die("Connection failed: " . $dbc->connect_error); }
$result=mysqli_query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>userID</th><th>first_name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["userID"]."</td><td>".$row["first_name"]."</td></tr>";
}
echo "</table>"; } else {
echo "0 results"; }
}
$dbc->close();
?>
这是连接文件
<?php
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', 'root');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'Test');
// Make the connection:
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' );
?>
推荐答案
立即尝试一下.您在同一文档中使用mysqli和mysql.这个somtime会导致问题.
give this a go. you were using mysqli and mysql in the same document. this somtime causes issues.
require_once ('mysqli_connect.php');
$q = "SELECT * FROM testview";
$r = mysqli_query($dbc, $q);
//there was no real need to check the connection, you should be doing this in your connection script.
//you where using 'mysqli' above and 'mysql' below.
$row = mysqli_fetch_array($r);
if ($r) {
echo "<table><tr><th>userID</th><th>first_name</th></tr>";
while ($row = mysqli_fetch_array($r)){
echo "<tr><td>" . $row["userID"] . "</td><td>" . $row["first_name"] . " " . $row["last_name"] . "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
close($conn);
这篇关于PHP选择SQL查看无输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文