【问题标题】:PhpEd Debugger show variable empty valuePhpEd 调试器显示变量空值
【发布时间】:2011-06-05 05:52:58
【问题描述】:

有谁知道为什么调试器在该脚本中显示 $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


?>

【问题讨论】:

    标签: php mysql oop mysqli phped


    【解决方案1】:

    嘿国防部,我认为你 $mysqldb 为空,因为当它为空时,你永远不会修改任何错误或警告 我在其他情况下测试它,例如没有用户名或密码。
    $mysqli = new mysqli($mysqlhost, $mysqluser, $mysqlpasswd, $mysqldb);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-14
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      • 2021-02-17
      相关资源
      最近更新 更多