데이터베이스 클래스에 문제가 있습니다. 준비된 명령문 하나와 여러 매개 변수를 취하여 명령문에 바인드하고 명령문을 실행하여 결과를 다차원 배열로 형식화하는 메소드가 있습니다. 매개 변수 중 하나에 전자 메일 주소를 포함하기 전까지는 아무 것도 작동하지 않습니다. 전자 메일에는 @ 문자가 포함되어 있으며 모든 문자가 손상된 것으로 보입니다. 내가 매개 변수로 제공하는 경우 : @ char가 포함 된 문자열을 mysqli_stmt_bind_param과 바인드 할 수 없습니다.
$types = "ss" and $parameters = array("[email protected]", "testtest")
내가 오류 얻을 : 여기
Warning: Parameter 3 to mysqli_stmt_bind_param() expected to be a reference, value given in ...db/Database.class.php on line 63
은 방법 :
private function bindAndExecutePreparedStatement(&$statement, $parameters, $types) {
if(!empty($parameters)) {
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($statement, $types), &$parameters));
/*foreach($parameters as $key => $value) {
mysqli_stmt_bind_param($statement, 's', $value);
}*/
}
$result = array();
$statement->execute() or debugLog("Database error: ".$statement->error);
$rows = array();
if($this->stmt_bind_assoc($statement, $row)) {
while($statement->fetch()) {
$copied_row = array();
foreach($row as $key => $value) {
if($value !== null && mb_substr($value, 0, 1, "UTF-8") == NESTED) { // If value has a nested result inside
$value = mb_substr($value, 1, mb_strlen($value, "UTF-8") - 1, "UTF-8");
$value = $this->parse_nested_result_value($value);
}
$copied_row[$ke<y] = $value;
}
$rows[] = $copied_row;
}
}
// Generate result
$result['rows'] = $rows;
$result['insert_id'] = $statement->insert_id;
$result['affected_rows'] = $statement->affected_rows;
$result['error'] = $statement->error;
return $result;
}
내가 하나 개 제안을받은 것을 :
the array_merge is casting parameter to string in the merge change it to &$parameters so it remains a reference
그래서 해 보았습니다. (메서드의 세 번째 줄)에서 어떤 차이도 내지 않았다.
어떻게해야합니까? call_user_func_array없이 이것을 할 수있는 더 좋은 방법이 있습니까?
갱신
: 나는이 문제를 해결하는 적은 꽤 방법을 발견했다. 내가 한 것은 루프로 새로운 참조 배열을 만들고 그 대신에 하나의 참조 배열을 사용하는 것입니다.private function bindAndExecutePreparedStatement($statement, $parameters, $types)
{
if(!empty($parameters)) {
$parameters_references = array();
foreach($parameters as $key => $parameter) {
$parameters_references[] = &$parameters[$key];
}
call_user_func_array('mysqli_stmt_bind_param',
array_merge(array($statement, $types), $parameters_references));
}
....
저는 PDO로이 문제를 해결하는 데 여전히 관심이 있습니다. 다른 기능도 많이 갖고있는 것처럼 보입니다. 나는 아직 그것을 사용하는 법을 배우지 못했다.
고마워요, 저는 약간의 독서를하러갑니다. 경우 {\ n 개인 기능 bindAndExecutePreparedStatement ($ 문, $ 매개 변수, $ 유형) ( $ parameters_references = 배열 {:-) – Tirithen
나는이 문제를 해결하는 적은 꽤 방법을 발견 ($ 매개 변수) (빈!)); foreach ($ parameters는 $ key => $ 매개 변수) { $ parameters_references [] = & $ parameters [$ key]; } call_user_func_array ('mysqli_stmt_bind_param', array_merge (array ($ 문형, $ 유형), $ parameters_references)); } .... 저는 PDO로이 문제를 해결하는 데 여전히 관심이 있습니다. 다른 기능도 많이 갖고있는 것처럼 보입니다. 나는 아직 그것을 사용하는 법을 배우지 못했다. – Tirithen
위의 설명은 다소 엉망이되었지만 내가 한 것은 루프로 새로운 참조 배열을 만들고 그 대신에 루프를 사용하는 것이 었습니다. – Tirithen