【问题标题】:PHP Fatal Error, Call to undefined method mysqli_stmt::get_result()PHP 致命错误,调用未定义的方法 mysqli_stmt::get_result()
【发布时间】:2013-06-02 20:20:57
【问题描述】:

在尝试将代码切换到实时服务器时,我似乎遇到了一个奇怪的问题。它可以在我的本地 WAMP 服务器上正常运行,但是在我的实时服务器上,当我尝试从数据库中提取信息并将其放入表中时,我的 error_log 中的问题标题中出现错误。

这是导致错误的代码:

<?php
  $query            = 'SELECT * FROM APPLICATIONS';
  $stmt             = $dbConnection->prepare($query);
  $stmt->execute();
  $result           = $stmt->get_result();
  $num_applications = $result->num_rows;
?>

具体来说:$result = $stmt->get_result();

我联系了我的服务器主机以确保安装了正确版本的 PHP。他们让我将以下内容添加到我的 php.ini 文件中:

extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so

我这样做了,但它并没有解决问题。然后他们告诉我它必须是我的代码。从我读过的文档和在本地服务器上的体验来看,代码似乎是正确的,但也许我需要一个外部视角。

这是我称之为数据的表格:

<table class="table table-hover table-striped table-bordered table-condensed">
    <tr>
        <th style="text-align:center;">Application ID</th>
        <th style="text-align:center;">Last Name</th>
        <th style="text-align:center;">First Name</th>
        <th style="text-align:center;">Organization</th>
        <th style="text-align:center;">Title</th>
        <th style="text-align:center;">Link to View</th>
    </tr>

  <?php
    for ($i = 0; $i < $num_applications; $i++) {
      $row = $result->fetch_assoc();

      $id = $row['ID'];
      $last_name = $row['LAST_NAME'];
      $first_name = $row['FIRST_NAME'];
      $organization = $row['ORGANIZATION'];
      $title = $row['TITLE'];

      $link = '<a href="../view_application.php?id='.$id.'"><i class="icon-external-link" style="color:#1122CC;"></i></a>';

      echo
      "<tr>
        <td style='text-align:center;'>$id</td>
        <td style='text-align:center;'>$last_name</td>
        <td style='text-align:center;'>$first_name</td>
        <td style='text-align:center;'>$organization</td>
        <td style='text-align:center;'>$title</td>
        <td style='text-align:center;'>$link</td>
      </tr>";
    }
  ?>
</table>

评论者询问 $dbConnection 是在哪里定义的,在文件的前面:

<?php
    $db_host = 'localhost';
    $db_port = '3306';
    $db_username = 'user';
    $db_password = 'password';
    $db_primaryDatabase = 'dbname';

    // Connect to the database, using the predefined database variables in /assets/repository/mysql.php
    $dbConnection = new mysqli($db_host, $db_username, $db_password, $db_primaryDatabase);

    // If there are errors (if the no# of errors is > 1), print out the error and cancel loading the page via exit();
    if (mysqli_connect_errno()) {
        printf("Could not connect to MySQL databse: %s\n", mysqli_connect_error());
        exit();
    }
?>

【问题讨论】:

  • 您是否使用低于 5.3 的 PHP 版本? (哎呀,老...)
  • @Wrikken 我的托管服务器是 5.3,他们为我更新了它
  • 在执行查询后尝试检查 $stmt->error_list,看看它是否给了你任何东西。 (我认为您使用的是错误消息中的 mysqli,而不是标记的 PDO)
  • $dbConnection 定义在哪里?
  • PDO和mysqli是完全不同的扩展

标签: php mysql sql sqlite pdo


【解决方案1】:

只是问一下,你确定你添加的扩展已经加载了吗?

问题可能存在,也可能不存在。希望有所帮助。

【讨论】:

  • 欢迎来到 StackOverflow!这似乎作为评论比作为答案更好;一旦您在网站上获得足够的reputation,您就可以在任何地方发表评论。
【解决方案2】:

mysqli_stmt :: get_result 仅适用于 mysqlnd 包(php 扩展)。

(php5-mysqlnd)不在(php5-mysql)中

【讨论】:

    猜你喜欢
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    相关资源
    最近更新 更多