Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 准备好的语句在带有MYSQLI扩展的函数中不起作用_Php_Mysql_Mysqli_Prepared Statement - Fatal编程技术网

Php 准备好的语句在带有MYSQLI扩展的函数中不起作用

Php 准备好的语句在带有MYSQLI扩展的函数中不起作用,php,mysql,mysqli,prepared-statement,Php,Mysql,Mysqli,Prepared Statement,我现在已经花了3个多小时试图使这段代码与php中的mysqli扩展正常工作。我已经知道有一个userid为4的用户,但是当我尝试将mysql prepared语句与[MYSQLI EXT]一起使用时,代码失败,如果它通过了测试,我只看到一个空白页。谁来帮帮我 下面是php中的代码snipe <?php //testing... require_once('connections/connections.php'); ini_set('display_errors',true); $rec

我现在已经花了3个多小时试图使这段代码与php中的mysqli扩展正常工作。我已经知道有一个userid为4的用户,但是当我尝试将mysql prepared语句与[MYSQLI EXT]一起使用时,代码失败,如果它通过了测试,我只看到一个空白页。谁来帮帮我

下面是php中的代码snipe

<?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();

在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();

完成了任何基本调试,比如检查准备/执行是否实际成功?除非您在其他地方启用了异常,否则您的所有代码都只是假设不会出错。最好是将数据传递到函数中,而不是使其出错global@Dennisrec谢谢,只是一个小小的错误我忘了,但是谢谢。