0
我找不到任何適當的例子如何在codeigniter中執行多個插入查詢。我已經嘗試在模型中創建一個函數,其中包含多個插入查詢。我總是首先查詢成功,其他人根本沒有執行。我已經嘗試使用事務:$ this-> db-> trans_start();我已經嘗試使用事務:$ this-> db-> trans_start(); 在我的情況如下:$ db-> trans_start();和課程$ db-> trans_complete();Codeigniter多插入查詢
但這並沒有幫助。始終只能首先插入執行的查詢。我應該怎麼做才能在一個功能中執行所有插入/更新/刪除查詢?
例子:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Deposit_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
public function inputdeh()
{
$this->load->helper('url');
$CI =& get_instance();
$db = $CI->load->database('local', TRUE);
$id_member = $this->input->post('id_member');
$jumlah = $this->input->post('jumlah');
$ket1 = $this->input->post('ket');
$ket = 'WEB/'.$ket1;
$saldoawal = $db->query("select saldo from member where id_member='$id_member'");
$saldoawa['saldo'] = $saldoawal->row('saldo');
$saldoaw = $saldoawa['saldo'];
$saldoak = $saldoaw + $jumlah;
//$_POST[jumlah]=number_format($_POST['jumlah'],".");
//$saldoak = number_format($saldoak);
//$dep = number_format(floatval($jumlah));
$result = $db->query("select nama from member where id_member='$id_member'");
$namar['nama'] = $result->row('nama');
$nama = $namar['nama'];
$resulthp = $db->query("select hp from member_hp where id_member='$id_member' LIMIT 1 OFFSET 0");
$hpr['hp'] = $resulthp->row('hp');
$nohp = $hpr['hp'];
//$now = 'NOW()';
$user = 'adminweb';
$data = array(
'id_member' => $this->input->post('id_member'),
'nama' => $nama,
'jml' => $this->input->post('jumlah'),
'saldo_awal' => $saldoaw,
'saldo_akhir' => $saldoak,
'kode_trx' => '1',
'status' => '1',
'ket' => $ket,
'user_input' => $user,
);
$db->set('tgl_transaksi', 'NOW()', FALSE);
$db->set('tgl_input', 'NOW()', FALSE);
return $db->insert('transaksi', $data);
$logsaldodata = array(
'id_member' => $this->input->post('id_member'),
'saldo' => $saldoaw,
'act' => $this->input->post('jumlah'),
'ket' => 'Deposit Tambah~True#',
);
$db->set('tgl', 'NOW()', FALSE);
$db->set('ref', 'last_insert_id()', FALSE);
return $db->insert('log_saldo', $logsaldodata);
}
}
非常感謝Damien Pirsy,在T.T.解決之前我沒有注意到! – bandungeuy 2014-11-25 06:28:10