Codeigniterでは、複数の挿入を行うSQL文字列を作成すると、それぞれの挿入されたIDを取得するにはどうすればよいですか?codeigniterに一括挿入のIDを取得する方法は?
// Prepare the SQL
$sql = '';
$chunk = array(array(), array(), array()); // The elements are arrays
foreach($chunk as $arr){
// The first field is the primary key (INT NOT NULL auto_increment)
$sql .= "(NULL, {$arr[0]}, {$arr[1]}, {$arr[2]}, {$arr[3]}, {$arr[4]})";
if($arr!= $last) $sql .= ', ';
}
// Start inserting into the db
$this->db->trans_start();
$this->db->query('INSERT INTO my_table VALUES '.$sql);
// A few other queries go here which need the IDs of the previous insert
$this->db->trans_complete();
これは私のトランザクションを初めて使用したときです。
あなたは管理された方法を共有して、挿入された値のIDを取得できますか? – Searock