$query = User::find() ->where(['id'=>[1,2,3,4]) ->select(['username']) // get the AR raw sql in YII2 $commandQuery = clone $query; echo $commandQuery->createCommand()->getRawSql(); $users = $query->all();
今天在项目运行过程中,一直报一个org.hibernate.exception.GenericJDBCException: could not insert 异常,Root Cause是IBM DB2 ErrorCode=-180,sqlstate=22007,经过Google,发现这个错误的原因是因为Timestamp的格式不规范导致,但是具体是哪一项,却不太清楚,如果能够打印出导致问题的SQL语句,那么对于这类问题的定位就会非常容易了. 在Hibernate的配置文件hibernate.c