我正在第一次使用准备语句工作,但是我陷入了这个错误。出于某种原因,我不能通过绑定类型作为参数?绑定值时的问题
我的代码:
function insert($table, $columns = array(), $bindTypes, $values = array()) {
// Store connection.
$connection = connection();
$columnValues = null;
$index = 1;
// Prepare unassigned value string.
foreach ($columns as $column) {
$columnValues .= '?';
if ($index < count($columns)) {
$columnValues .= ', ';
}
$index++;
}
// Debugg purpose: echo query example:
echo "INSERT INTO {$table} (" . implode(', ', $columns) . ") VALUES ({$columnValues})";
// Prepare statement.
$statement = $connection->prepare("INSERT INTO {$table} (" . implode(', ', $columns) . ") VALUES ({$columnValues})");
$statement->bind_param($bindTypes, implode(', ', $values));
}
insert('test', array('name'), 'i', array(1));
如果我回应查询的例子,我得到 “INSERT INTO测试(名称)VALUES(?)”。
请让我免费我仍然是一个学习noob。
注意:由于[... $ values](http://php.net/functions.arguments#functions.variable-arg-list)语法,PHP/5.6 +是必需的。 –