我正在使用insert_batch这么久,我无法弄清楚它是如何工作的,所以我需要一些指导来解决这个错误。
A PHP Error was encountered
Severity: Warning
Message: array_keys() expects parameter 1 to be array, boolean given
Filename: database/DB_active_rec.php
Line Number: 1109
A PHP Error was encountered
Severity: Warning
Message: sort() expects parameter 1 to be array, null given
Filename: database/DB_active_rec.php
Line Number: 1110
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: database/DB_active_rec.php
Line Number: 1140
A Database Error Occurred
You must use the "set" method to update an entry.
Filename: C:\xampp\htdocs\squline_beta\dashboard\system\database\DB_active_rec.php
Line Number: 1054
我正在使用CI 2并且出现错误,因为我以这种方式调用insert_batch:
返回$ this-> db-> insert_batch('tbl_quiz_answer',$ data);
$ data转储如下所示:
array(9) {
[0]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3248)
["id_student"]=>
string(3) "305"
["answer"]=>
string(3) "asd"
}
[1]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3247)
["id_student"]=>
string(3) "305"
["answer"]=>
string(6) "asdasd"
}
[2]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3246)
["id_student"]=>
string(3) "305"
["answer"]=>
string(3) "asd"
}
[3]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3245)
["id_student"]=>
string(3) "305"
["answer"]=>
string(1) "b"
}
[4]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3244)
["id_student"]=>
string(3) "305"
["answer"]=>
string(1) "b"
}
[5]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3243)
["id_student"]=>
string(3) "305"
["answer"]=>
string(1) "d"
}
[6]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3242)
["id_student"]=>
string(3) "305"
["answer"]=>
string(1) "a"
}
[7]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3241)
["id_student"]=>
string(3) "305"
["answer"]=>
string(1) "a"
}
[8]=>
array(4) {
["id_quiz_master"]=>
string(3) "500"
["id_quiz_question"]=>
int(3240)
["id_student"]=>
string(3) "305"
["answer"]=>
string(6) "asdasd"
}
}
请帮助我,我不知道我做错了什么。
答案 0 :(得分:0)
以下是如何为insert_batch构建数组的示例。它可能不完全像您需要它但它可以正常工作并执行插入。
public function post_message( $post, $user_id )
{
$message_data = array();
foreach ($post[ 'to_id' ] as $key) {
$message = array(
'from_id' => $user_id,
'to_id' => $key,
'message' => $post[ 'message' ],
'sent_date_time' => date( 'Y-m-d H:i:s' )
);
$message_data[] = $message;
}
$this->db_central->insert_batch( 'messages', $message_data );
}