2009-04-16 3 views

답변

15
array($stmt, 'bindparams') 

더 이상 (및 mysqli은 PHP 5는 그래서 이것은 이전의 결함과 같은 당신이 앞에 &를 사용할 필요가 없습니다 PHP 5부터, 객체 $stmt에 방법 bind_params을 식별 PHP의 방법입니다 게시하다).

당신은 너무

call_user_func_array(array($stmt, 'bindparams'), $array_of_params); 

는 기본적으로

$stmt->bind_params($array_of_params[0], $array_of_params[1] ... $array_of_params[N]) 
+0

감사합니다 ... 나는 오늘 좋은 하루가 될거라고 말할 수 있습니다. – johnnietheblack

1

뜻이 할 수있는 많은 선웃음있는 방법은 유사한 예를 here

을 볼 수 있습니다.

이 준비된 문 작성 :

select * from mytable 
where status = ? and (userid = ? or ?) 
and (location = ? or ?) 
order by `date` desc, time desc 
limt ? 

과 같이 결합 할 수있는 인수 전달합니다

$stmt = $mysqli->prepare([statement above]); 
$stmt->bind_param("siiiii", 
    "active", $userid, $userid == "ALL", 
    $location, $location == "ALL", 
    $limit); 

술어를 (user_id = ? or ?) USER_ID 첫 번째 대체 매개 변수 또는시 같을 때 true가됩니다 두 번째로 대체 된 매개 변수는 true입니다.

$user_id은 int 값으로 변환 될 때 값이 문자열 표현 일 때 값이되고, 그렇지 않으면 0입니다. $userid == "ALL"이라는 표현식은 부울로 평가되며 bind_param으로 전달됩니다. bind_param은 매개 변수가 부울 (format string은 string, int, double 및 blob 만 이해합니다)이라고 말할 수 없으므로 bind_param은 부울을 int로 변환합니다.

데이터베이스의 user_id 또는 location_id가 0이 아니라면 괜찮습니다.

+0

+1 내 문제도 해결했습니다. :) – johnnietheblack

2

내가 아는 한, 예를 들어 다음과 같은 결과를 전달할 수 없습니다. $userid == "ALL" ~ mysqli-statement-Object의 bind_param 메소드.이 메소드는 매개 변수를 참조로 전달하기를 원하기 때문입니다. 명백히 이것은 "제자리에서"평가 된 표현식의 결과로 가능하지 않습니다. 해결책으로

, 제가

그 추천
$userIdEmpty = $userid == "ALL"; 
$locationEmpty = $location = "ALL"; 
$stmt->bind_param("siiiii", 
    "active", $userid, $userIdEmpty, 
    $location, $locationEmpty, 
    $limit); 

에 프로그램의 두 번째 부분을 변경 부울 연산의 결과가 참조에 의해 전달 될 수있다.