bind_param을 동적으로 빌드하려면 다른 SO 게시물에서이 파일을 찾았습니다.PHP의 동적 mysqli bind_param 인수에 대한 간단한 해결책은 무엇입니까?
call_user_func_array(array(&$stmt, 'bindparams'), $array_of_params);
누군가 나를 보통 영어로 부러 뜨릴 수 있습니까? 특히 첫 번째 인수가 배열이라는 점을 잊어 버립니다.
bind_param을 동적으로 빌드하려면 다른 SO 게시물에서이 파일을 찾았습니다.PHP의 동적 mysqli bind_param 인수에 대한 간단한 해결책은 무엇입니까?
call_user_func_array(array(&$stmt, 'bindparams'), $array_of_params);
누군가 나를 보통 영어로 부러 뜨릴 수 있습니까? 특히 첫 번째 인수가 배열이라는 점을 잊어 버립니다.
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])
뜻이 할 수있는 많은 선웃음있는 방법은 유사한 예를 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이 아니라면 괜찮습니다.
+1 내 문제도 해결했습니다. :) – johnnietheblack
내가 아는 한, 예를 들어 다음과 같은 결과를 전달할 수 없습니다. $userid == "ALL"
~ mysqli-statement-Object의 bind_param 메소드.이 메소드는 매개 변수를 참조로 전달하기를 원하기 때문입니다. 명백히 이것은 "제자리에서"평가 된 표현식의 결과로 가능하지 않습니다. 해결책으로
$userIdEmpty = $userid == "ALL";
$locationEmpty = $location = "ALL";
$stmt->bind_param("siiiii",
"active", $userid, $userIdEmpty,
$location, $locationEmpty,
$limit);
에 프로그램의 두 번째 부분을 변경 부울 연산의 결과가 참조에 의해 전달 될 수있다.
감사합니다 ... 나는 오늘 좋은 하루가 될거라고 말할 수 있습니다. – johnnietheblack