2016-10-17 2 views
2

PHP로 mysqli extention으로이 코드가 제대로 작동하도록 3 시간 이상을 보냈다. 나는 이미 userid 4가있는 사용자가 있음을 알고 있지만 [MYSQLI EXT]가있는 mysql prepared statement를 사용하려고하면 코드가 실패하고 테스트를 통과하면 빈 페이지 만 보입니다. 누가 좀 도와주세요.준비된 문장이 MYSQLI 함수에서 작동하지 않는다 EXTERNAL

코드 도촬은 아래 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(); 
+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(); 
+0

데이터를 함수로 전달하는 것이 가장 좋을 것입니다. –

+1

@Dennisrec 덕분에, 약간의 실수를 저도 잊지 만 감사합니다. – Zuckerberg

관련 문제