How to detect the last insert ID within a transaction in Yii using DAO?

后端 未结 3 1122
迷失自我
迷失自我 2021-01-12 04:59

That\'s the source code, I need to detect the ID (see the marked position between the two queries below).

$connection = Yii::app()->db;
$transaction=$conn         


        
3条回答
  •  不知归路
    2021-01-12 05:17

    i created this to solve that issue

    public static function getAutoIncrement($table_name)
    {
        $q = new Query();
        $res = $q->select("AUTO_INCREMENT")
            ->from('INFORMATION_SCHEMA.TABLES')
            ->where("TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '" . $table_name . "'")
            ->one();
        if ($res)
            return $res["AUTO_INCREMENT"];
        return false;
    }
    

提交回复
热议问题