PhpEd 调试器显示变量空值
有谁知道为什么调试器在该脚本中显示 $result 和 $mysqli 的空值?
<?php
// show SELECT result as HTML table
function show_table($result) {
if(!$result) {
echo "<p>No valid query result.</p>\n";
return;
}
if($result->num_rows>0 && $result->field_count>0) {
echo "<table>";
// column headings
echo "<tr>";
foreach($result->fetch_fields() as $meta)
printf("<th>%s</th>", htmlspecialchars($meta->name));
echo "</tr>\n";
// content
// row fetch row
while($row = $result->fetch_row()) {
echo "<tr>";
foreach($row as $col)
printf("<td>%s</td>", htmlspecialchars($col));
echo "</tr>\n";
}
echo "</table>\n";
}
}
require_once 'password.php';
// connect to MySQL
$mysqli = new mysqli($mysqlhost, $mysqluser, $mysqlpasswd, $mysqldb);
if(mysqli_connect_errno()) {
echo "<p>Sorry, no connection! ", mysqli_connect_error(), "</p>\n";
exit();
}
// show SELECT result with show_table
if($result = $mysqli->query("SELECT * FROM titles")) {
show_table($result);
$result->close();
}
// disconnect
$mysqli->close();
?>
</body></html>
<?php
?>
Does anyone know why debugger shows an empty value for $result and $mysqli in that script?
<?php
// show SELECT result as HTML table
function show_table($result) {
if(!$result) {
echo "<p>No valid query result.</p>\n";
return;
}
if($result->num_rows>0 && $result->field_count>0) {
echo "<table>";
// column headings
echo "<tr>";
foreach($result->fetch_fields() as $meta)
printf("<th>%s</th>", htmlspecialchars($meta->name));
echo "</tr>\n";
// content
// row fetch row
while($row = $result->fetch_row()) {
echo "<tr>";
foreach($row as $col)
printf("<td>%s</td>", htmlspecialchars($col));
echo "</tr>\n";
}
echo "</table>\n";
}
}
require_once 'password.php';
// connect to MySQL
$mysqli = new mysqli($mysqlhost, $mysqluser, $mysqlpasswd, $mysqldb);
if(mysqli_connect_errno()) {
echo "<p>Sorry, no connection! ", mysqli_connect_error(), "</p>\n";
exit();
}
// show SELECT result with show_table
if($result = $mysqli->query("SELECT * FROM titles")) {
show_table($result);
$result->close();
}
// disconnect
$mysqli->close();
?>
</body></html>
<?php
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿 DOD 我认为你 $mysqldb 为空,因为当它为空时你永远不会修改任何错误或警告
我在其他情况下测试它,例如没有用户名或密码。
<代码>
$mysqli = new mysqli($mysqlhost, $mysqluser, $mysqlpasswd, $mysqldb);
hey DOD i think you $mysqldb is null because when its null you never revise any error or warning
i test it in other case such as without user name or password.
$mysqli = new mysqli($mysqlhost, $mysqluser, $mysqlpasswd, $mysqldb);