准备好的语句不适用于具有MYSQLI EXTENTION的函数

时间:2016-10-17 17:13:37

标签: php mysql mysqli prepared-statement

我现在花了3个多小时试图使这个代码在php中使用mysqli extention正常工作。我已经知道有一个用户使用userid 4但是当我尝试使用带有[MYSQLI EXT]的mysql预编译语句时,代码失败了,如果它通过了测试,我只看到一个空白页面。有人请帮助我。

代码狙击在php下面。

<?php

//testing...
require_once('connections/connections.php');
ini_set('display_errors',true);
$received_id=4;//from the client...

function synchronize(){
    global $con, $received_id;

    $check_db=$con->prepare("SELECT FIRSTNAME,LASTNAME,USERNAME FROM SUPERDATATABLE WHERE USERID=?");
    $check_db->bind_param('i',$received_id);
    $check_db->execute();

    if($check_db->num_rows>0){
        $check_db->bind_result($first_name,$last_name,$user_name);
        $check_db->fetch();
        echo $first_name.'+'.$last_name.'+'.$user_name;
    }else{
        echo 'Sorry, but this did not work';
    }

}synchronize();

1 个答案:

答案 0 :(得分:0)

你在store_results()函数中缺少。请尝试下面的代码,看看它是否适合您,但我已经测试过了。

<?php
//testing...
require_once('connections/connections.php');
ini_set('display_errors',true);

$received_id=4;//from the client...


function synchronize(){
    global $con, $received_id;

    $check_db=$con->prepare("SELECT FIRSTNAME,LASTNAME,USERNAME FROM SUPERDATATABLE WHERE USERID=?");
    $check_db->bind_param('i',$received_id);
    $check_db->execute();


    #typically required....
    #you are missing this statement which is required to check the length of selected rows
    $check_db->store_result();


    if($check_db->num_rows>0){
        $check_db->bind_result($first_name,$last_name,$user_name);
        $check_db->fetch();
        echo $first_name.'+'.$last_name.'+'.$user_name;
    }else{
        echo 'Sorry, but this did not work';
    }

}synchronize();