duandui2803 2014-11-19 01:43
浏览 66

如何在uuid codeigniter中检索最后一个插入ID

i have a trouble when retrieve last insert id in codeigniter. when i try to debug like var_dump(); the output just send int(0)

i use uuid as id with primary key. this is the code:

$this->db->set('id_customer','uuid_short()',FALSE);
    $query = $this->db->insert('customer',$data);
    $id = $this->db->insert_id();
    echo var_dump($id);

    if($query)
    {
        $array = array(
            'kode_trans' => 'uuid()',
            'trans_date' => 'NOW()'
            );

        $this->db->set('id_customer','$id');
        $this->db->set($array,'',FALSE);
        $this->db->insert('transaction_header');

        return $id;
    }else{
        return FALSE;
    }

im newbie in ci. there is something wrong with my code?

  • 写回答

1条回答 默认 最新

  • dtg7662 2014-11-19 08:48
    关注

    The "insert_id" function uses PHP's mysql_insert_id function, which returns "The ID generated for an AUTO_INCREMENT column by the previous query on success, 0 if the previous query does not generate an AUTO_INCREMENT value"

    You could try it this way;

    $id = uuid_short();
    $data['id_customer'] = $id;
    
    $query = $this->db->insert('customer', $data);
    if ( $query )
    {
        $array = array(
        'kode_trans' => 'uuid()',
        'trans_date' => 'NOW()'
    );
    
    $query = $this->db->insert('transaction_header', $array);
    return $id; 
    }
    else
    {
        return false;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?