生成字符串stmt- $> bind_param然而,当我碰到一个嗝 - 我的代码来生成SQL语句工作正常。 代码如下:
$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]:在类型定义字符串元素的数量不匹配在绑定变量的数目...”
有任何想法吗?