簡體   English   中英

"PHP 致命錯誤:調用未定義函數 mysqli_stmt_get_result()"

[英]PHP Fatal error: Call to undefined function mysqli_stmt_get_result()

我不斷收到錯誤 PHP 致命錯誤:調用未定義函數 mysqli_stmt_get_result()。 我使用的是 PHP 5.6 版,並在我的托管服務提供商 c 面板中啟用了擴展 mysqlind,但我不知道為什么我仍然收到此錯誤。 我研究並發現每次我需要啟用 mysqli nd 才能使用 mysqli_stmt_get_result。 任何人都可以幫助\/教我做錯了什么。 謝謝你。

注冊.PHP:

<?php
    session_start();
    include '../dbh.php';

    $respond = array(
        'status' => true,
        'message' => 'There was an error',
        'redirect',
        'errors'
    );

    if (isset($_POST['submit'])) {

        $first = $_POST['first'];
        $last  = $_POST['last'];
        $email = $_POST['email'];
        $pwd   = $_POST['pwd'];

        $errorEmpty = false;
        $errorEmail = false;


        if (empty($first) || empty($last) || empty($email) || empty($pwd)) {

            $respond['errors'][]   = "Please fill out all fields!";
            $respond['errorEmpty'] = true;

        } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $respond['errors'][]   = "Please enter a valid email address!";
            $respond['errorEmail'] = true;

        } else {
            $sql  = "SELECT email FROM user WHERE email= ? ";
            $stmt = mysqli_prepare($conn, $sql);
            mysqli_stmt_bind_param($stmt, 's', $email);
            mysqli_stmt_execute($stmt);
            $result   = mysqli_stmt_get_result($stmt);  //This is where I getting my error
            $num_rows = mysqli_num_rows($result);
            if ($num_rows > 0) {
                $respond['errors'][]   = "That email address already exists!";
                $respond['errorEmail'] = true;
            }

            else {
                $encryptpwd = password_hash($pwd, PASSWORD_DEFAULT);
                $sql        = "INSERT INTO user (first, last, email, pwd) VALUES (?,?,?,?)";
                $stmt       = mysqli_prepare($conn, $sql);
                mysqli_stmt_bind_param($stmt, 'ssss', $first, $last, $email, $password_hash);

                if (mysqli_stmt_execute($stmt)) {

                    $userID = mysqli_insert_id($conn);
                    $status = 1;
                    $sql2   = "INSERT INTO profileImg (email, status) VALUES(?,?)";
                    $stmt2  = mysqli_prepare($conn, $sql2);
                    mysqli_stmt_bind_param($stmt2, 'si', $email);
                    mysqli_stmt_execute($stmt);

                    $_SESSION['id'] = $userID;

                    $respond['redirect'] = "../profile.php?id=$userID";
                }
            }
        }
    }
    echo json_encode($respond);
    ?>

為了防止其他人在啟用 mysqlnd 本機驅動程序時試圖找出為什么這不起作用的幾個小時尖叫。 這是因為您需要確保啟用兩個本機驅動器。 如果您希望使用此功能,則需要在您的服務器上啟用 mysqlnd 和 nd_mysqli。

否則,僅啟用 mysqlnd 本機驅動程序不包括 mysqli_stmt_get_result 函數,因為這顯然駐留在 nd_mysqli 本機驅動程序中。 不幸的是,大多數文檔只討論過 mysqlnd 本機驅動程序。

一旦啟用了兩個本機驅動程序,此功能將按文檔說明工作。

哦,在我的托管服務器上,您需要禁用\/取消選中 mysqli 以啟用 nd_mysqli。

您是否正確安裝了 mysqlnd 驅動程序? 根據手冊中的評論:

如果您沒有安裝/加載任何 mysqlnd,則在嘗試調用“mysqli_stmt_get_result()”時將獲得未定義的引用。

此外, 這里這里也有關於這個問題的討論。

最后,這里有一個論壇,討論有關將驅動程序與 cpanel 一起使用的信息,您可能會發現這些信息很有用。

我遇到了同樣的問題(“PHP 致命錯誤:調用未定義的函數 mysqli_stmt_get_result()”),只需要更改服務器的 php 版本,也就是自動設置為 5.6 到 7.2,並確保檢查了 nd_mysqli . 請注意,mysqlnd 被禁止代替 nd-mysqli。

腳步:
在 cpanel 中找到更改 php 版本部分
選擇當前7.2最高版本的php
確保從擴展列表中檢查 nd_mysqli
如果出現任何錯誤,請嘗試取消選中 mysqlnd

您正在使用獲取數據的程序方式。

如果可能,您可以使用面向對象的方式,因此不需要在服務器上啟用 nd_mysqli。

$sql = "SELECT * FROM users WHERE id=?"; // SQL with parameters
$stmt = $conn->prepare($sql); 
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
$user = $result->fetch_assoc(); // fetch data 

如果它與您的 php 代碼匹配,只需檢查您服務器上的數據庫表名。 在服務器 sql admin 的右側,您可以找到此鏈接。 單擊“創建 php 代碼”,然后使用顯示的確切表名,如下所示:
$sql = "SELECT * FROM 'users' WHERE id=?"; 鏈接圖片<\/a>在我看來,代碼如下所示: table name image<\/a> $sql = "SELECT * FROM 'pending_products' WHERE id=?";

"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM