我喜欢这样的数据:
$data = Array
(
[0] => Array
(
[kode_pbt] => PBT3-2012-10-19
[kodebr] => 8992802618731
[harga] => 25905.00
[jml] => 1
[subtotal_harga] => 25905
)
[1] => Array
(
[kode_pbt] => PBT3-2012-10-19
[kodebr] => 8992388112401
[harga] => 1340.00
[jml] => 1
[subtotal_harga] => 1340
)
)
我的问题是当我想插入数据库时 白色此代码:$ this-> db-> insert($ table,$ data) 我收到一个错误: 消息:数组到字符串转换 我已更改为$ this-> db-> insert_batch($ table,$ data),但我收到错误'500内部服务器错误'。 谢谢你的帮助。
这是我在控制器中的完整功能代码:
function save_pbt($kode = -1) {
$pbt_detail = array();
$pbt_data = array(
'kode_pbt' => trim($this->input->post('kode_pbt')),
'unit_pemakai' => trim($this->input->post('unit_pemakai')),
'jml_item' => trim($this->input->post('jml_item')),
'total_harga' => trim($this->input->post('total_harga')),
'tgl_pbt' => date('Y-m-d'),
'status' => 0
);
for ($i = 0; $i <= $this->input->post('max_i'); $i++) {
if ($this->input->post('kodebr' . $i)) {
$detail_pbt = array(
'kode_pbt' => $this->input->post('kode_pbt'),
'kodebr' => $this->input->post('kodebr' . $i),
'harga' => $this->input->post('beli' . $i),
'jml' => $this->input->post('jml' . $i),
'subtotal_harga' => $this->input->post('subtotal' . $i)
);
array_push($pbt_detail, $detail_pbt);
}
}
$this->db->trans_begin();
$this->Pbt_model->insert_pbt($pbt_data);
$this->Pbt_model->insert_detail_pbt($pbt_detail);
if ($this->db->trans_status() == FALSE) {
$this->db->trans_rollback();
echo "TRANSACTION ROLLBACK";
} else {
$pbt_data['detail'] = $pbt_detail;
$url = SERVER_SIKOPIT . 'service/service?process=pbt&api_key=' . API_KEY;
$response = json_encode($this->rest_helper($url, $pbt_data, "POST"));
echo $response;
$response = json_decode($response);
if ($response->status == true) {
$this->db->trans_commit();
echo "TRANSACTION SUCCESS";
redirect(site_url('receivings'));
} else {
$this->db->trans_rollback();
echo "INSERT PBT BARU GAGAL !!";
echo "TRANSACTION ROLLBACK";
}
}
}