if ($connection->createCommand()->insert(’{{employees}}’, $columns) >= 1) {
......
}
或者直接
if ($connection->createCommand()->insert(’{{employees}}’, $columns)) {
......
}
当连续大量的数据(2000)循环插入的时候,貌似会有判断失误的情况。
MySQL innodb + Yii1.1.7
if ($connection->createCommand()->insert(’{{employees}}’, $columns) >= 1) {
......
}
或者直接
if ($connection->createCommand()->insert(’{{employees}}’, $columns)) {
......
}
当连续大量的数据(2000)循环插入的时候,貌似会有判断失误的情况。
MySQL innodb + Yii1.1.7
如果大量数据插入的时候,最好加上事务!
加上事务不成功便成仁的方式貌似不是很适合客户的要求。
MySQL支持这种语法格式,如果你不需要事务,可以尝试使用批处理插入,性能更高
insert into table(col1, col2) VALUES (val1,val2), (val3,val4), (val5, val6)
使用循环拼接字符串
values( '01 ', 'darwinwen', '22 ', 'darwinwen'),
$commend = $db -> createCommand();
for($i = 0 ; i< 1000; i++) {
if($i % 100 == 0) {
//执行这个方法完后返回文档说明很清楚,返回受影响的行数(number of rows affected by the execution.)
$rows = $commend.execute();
if($rows == 100) {
echo "成功"...
}
}
}
这样挺好的!