我使用codegniter框架将csv数据导入mysql数据库。我的数据库有两个表促销和promotion_product.promotion表是3个字段名称为promotion_id,name,start_date和end_date.promotion_id是促销表的主键.promotion_id是auto incrementmment.promotion_product表是5个字段id,promotion_id,sku,price ,地图。 promotion_id是此表的外键。我正在导入csv文件,这个table.csv字段是sku,price和map.i我没有得到如何插入promotion_id的promote_id,我正在使用last_insert_id.my代码如下:
我的模特是:
public function save_csv($data,$data1) {
$this->db->insert('promotion', $data1);
$insert_id = $this->db->insert_id();
print_r($insert_id);
$infile = $data['upload_data']['full_path'];
//print_r($infile);
$sql = "LOAD DATA INFILE '" . $infile . "'
INTO TABLE promotion_product
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\r'
IGNORE 1 LINES
(promotion_id,sku, price, map)";
print_r($sql);
$query = $this->db->query($sql);
//var_dump($query);
return $query;
}
答案 0 :(得分:0)