SQL 문을 생성하는 코드가 올바르게 작동합니다. 그러나 $ stmt-> bind_param에 대한 문자열을 생성 할 때 딸꾹질이 발생합니다. 다음과 같이 코드는 다음과 같습니다PHP mysqli prepare - 동적으로 생성
$stmt = $mysqli->stmt_init(); if ($stmt->prepare ($sql)) { $bind_types = '"'; $bind_values = '';
if ($action == 'insert' || $action == 'update') {
reset ($array);
foreach ($array as $key => $value) {
if (is_string ($value)) { $type = 's'; } else if (is_int ($value)) { $type = 'i'; } else if (is_float ($value)) { $type = 'd'; } else { die ('Cannot determine type for ' . $key . ' => ' . $value . ''); }
$bind_types .= $type;
$bind_values .= $value . ', ';
//$stmt->bind_param ($type, $value);
}
}
if ($action == 'update' || $action == 'delete') {
if (is_string ($id_value)) { $type = 's'; } else if (is_int ($id_value)) { $type = 'i'; } else if (is_float ($id_value)) { $type = 'd'; } else { die ('Cannot determine type for ' . $id_column . ' => ' . $id_value . ''); }
$bind_types .= $type;
$bind_values .= $id_value . ', ';
//$stmt->bind_param ($type, $id_value);
}
$bind_types .= '"';
$bind_values = substr ($bind_values, 0, -2);
echo $bind_types . ', ' . $bind_values;
$stmt->bind_param ($bind_types, $bind_values);
$stmt->execute();
}
은 그 서식이 엉망이되었다. 읽을 수 없다면 사과드립니다.
나는 다음과 같은 오류가 점점 오전 :
"경고 : mysqli_stmt :: bind_param() [mysqli - stmt.bind-PARAM] : 유형 정의 문자열에있는 요소의 수에 바인드 변수의 수와 일치하지 않습니다 ... "
아이디어가 있으십니까?
그래서 많은'mysql_'와'마지막 시간에 mysqli'이 ... [PDO] 사용이 해킹 못생긴 볼 바인딩하려면 /book.pdo.php). –
나는 그것을 조사하고 있었다. 그러나 mysqli 대 PDO 사용에 대한 주장은 양측 모두에서 훌륭합니다. mysqli가 굴리는 방법이라고 생각했습니다. 아마. –
나는 많은 논의가 있었다는 인상을 받고 있지는 않았지만 지금은 논점을 살펴 보겠다. –