亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

調用未定義的方法mysqli_stmt :: get_result

調用未定義的方法mysqli_stmt :: get_result

慕尼黑5688855 2019-05-29 17:18:41
調用未定義的方法mysqli_stmt :: get_result這是我的代碼:include 'conn.php';$conn = new Connection();$query = 'SELECT EmailVerified, Blocked FROM users WHERE Email = ? AND SLA = ? AND `Password` = ? ';$stmt = $conn->mysqli->prepare($query);$stmt->bind_param('sss', $_POST['EmailID'], $_POST['SLA'], $_POST['Password']);$stmt->execute(); $result = $stmt->get_result();我在最后一行得到錯誤:調用未定義的方法mysqli_stmt :: get_result()這是conn.php的代碼:define('SERVER', 'localhost');define('USER', 'root');define('PASS', 'xxxx');define('DB', 'xxxx');class Connection{     /**      * @var Resource       */     var $mysqli = null;     function __construct(){         try{             if(!$this->mysqli){                 $this->mysqli = new MySQLi(SERVER, USER, PASS, DB);                 if(!$this->mysqli)                     throw new Exception('Could not create connection using MySQLi', 'NO_CONNECTION');             }         }         catch(Exception $ex){             echo "ERROR: ".$e->getMessage();         }     }}如果我寫這行:if(!stmt) echo 'Statement prepared'; else echo 'Statement NOT prepared';它打印'Statement NOT prepared'。如果我直接在IDE中運行查詢替換?用值標記,它工作正常。請注意,$ conn對象在項目中的其他查詢中正常工作。請幫忙.......
查看完整描述

4 回答

?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

因此,如果MySQL本機驅動程序(mysqlnd)驅動程序不可用,因此使用bind_result和fetch而不是get_result,代碼將變為:


include 'conn.php';

$conn = new Connection();

$query = 'SELECT EmailVerified, Blocked FROM users WHERE Email = ? AND SLA = ? AND `Password` = ?';

$stmt = $conn->mysqli->prepare($query);

$stmt->bind_param('sss', $_POST['EmailID'], $_POST['SLA'], $_POST['Password']);

$stmt->execute();

$stmt->bind_result($EmailVerified, $Blocked);

while ($stmt->fetch())

{

   /* Use $EmailVerified and $Blocked */

}

$stmt->close();

$conn->mysqli->close();


查看完整回答
反對 回復 2019-05-29
?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

你的系統缺少mysqlnd驅動程序!

如果您能夠在(基于Debian / Ubuntu的)服務器上安裝新軟件包,請安裝驅動程序:

sudo apt-get install php5-mysqlnd

然后重新啟動您的Web服務器:

sudo /etc/init.d/apache2 restart


查看完整回答
反對 回復 2019-05-29
?
慕婉清6462132

TA貢獻1804條經驗 獲得超2個贊

對于那些搜索$ result = stmt-> get_result()的替代方法的人我已經創建了這個函數,它允許你模仿$ result-> fetch_assoc()但直接使用stmt對象:

function fetchAssocStatement($stmt){
    if($stmt->num_rows>0)
    {
        $result = array();
        $md = $stmt->result_metadata();
        $params = array();
        while($field = $md->fetch_field()) {
            $params[] = &$result[$field->name];
        }
        call_user_func_array(array($stmt, 'bind_result'), $params);
        if($stmt->fetch())
            return $result;
    }

    return null;}

正如你所看到它創建一個數組并使用行數據獲取它,因為它在內部使用$ stmt-> fetch(),你可以像調用mysqli_result :: fetch_assoc一樣調用它(只需確保$ stmt對象)打開并存儲結果):

//mysqliConnection is your mysqli connection objectif($stmt = $mysqli_connection->prepare($query)){
    $stmt->execute();
    $stmt->store_result();

    while($assoc_array = fetchAssocStatement($stmt))
    {
        //do your magic
    }

    $stmt->close();}

希望這可以幫助。


查看完整回答
反對 回復 2019-05-29
  • 4 回答
  • 0 關注
  • 965 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號