-1
我试图做的是创建不同的插入语句 in for循环并在循环中执行它们。那可能吗?mysqli在for循环中插入不同的insert语句
这里的简化代码:
$mysqli = new mysqli("localhost", "user", "password", "database");
for($i=1; $i<10; $i++){
// $query string is created through code, so
// INSERT statement is varying after each loop.
// Lets say, in another step $query will be "INSERT INTO table (row4,row5) VALUES (?,?)";
// $params will be array("value4","value5");
$query = "INSERT INTO table (row1,row2,row3) VALUES (?,?,?)";
$param_type = "sss";
$params = array("value1","value2","value2");
$insert_stmt = $mysqli->prepare($query);
array_unshift($params, $param_type);
call_user_func_array(array($insert_stmt, 'bind_param'), refValues($params));
$insert_stmt->execute();
$insert_stmt->close();
}
我能得到什么,如果我运行这段代码是唯一一个插排和警告 “call_user_func_array()预计参数1是一个有效的回调,第一个数组成员不是有效的类名称或对象...“
所以我的问题是:如何准备和插入不同的查询和参数通过for循环?
-1。 – 2013-04-21 12:38:04
只有refValues函数不包括在内,我排除了在每个循环中构建不同查询的代码。我认为,展示我如何构建查询并不重要。 – woopata 2013-04-21 12:41:38
虽然错误信息很清楚。这使得这个问题重复http://stackoverflow.com/questions/15447133/mysqli-update-throwing-call-toa-a-member-function-bind-param-error – 2013-04-21 12:50:50