/** * 测试多行行对象插入 */ private function testRowInstanceInsert() { //insert into user_salt (`Uid`, `Salt`) values ('31', 'fdadsf'), ('32', 'aaadsf'), ('35', 'ddddd') ; $batch = array(); $row = \Model\Table\UserSalt::create()->createRow(); $row->Uid = 31; $row->Salt = "fdadsf"; $batch[] = $row; $row = \Model\Table\UserSalt::create()->createRow(); $row->Uid = 32; $row->Salt = "aaadsf"; $batch[] = $row; $row = \Model\Table\UserSalt::create()->createRow(); $row->Uid = 35; $row->Salt = "ddddd"; $batch[] = $row; $insert = \HuiLib\Db\Query::Insert()->batchSaveRows($batch); echo $insert->toString(); //$insert->query(); }
$re = $select->prepare()->execute(array('id' => 14)); //2.1.4 设置表、字段和别名 $select->table(array('AliasTable' => 'test')); //数组键是别名 $select->columns(array('AliasId' => 'id', 'AliasTest' => 'test')); //数组键是别名 //2.1.5 支持Join $select->join(array('AliasTable' => 'name'), 't.id=n.tid', 'n.name as sname, n.sid as bbid'); //表名、ON条件、获取字段 //2.1.6 发起查询 $select->query(); //或者这样 $connect->query($select->toString()); //2.2 插入部分 //获取插入对象 $insert = \HuiLib\Db\Query::Insert(); //2.2.1 键数组、值数组插入模式 //insert into test (field1, field2) values ('fvalue1', 'fvalue2') ; $insert->fields(array('field1', 'field2'))->values(array('fvalue1', 'fvalue2')); //insert into test (field1, field2) values ('fvalue1', 'fvalue2'), ('fvalue11', 'fvalue22') ; $insert->values(array('fvalue11', 'fvalue22')); //附加 前面的 //2.2.2 关联数组插入模式 //insert into test (field1, field2) values ('fvalue1', 'fvalue2'), ('fvalue11', 'fvalue22') ; $insert->kvInsert(array('field1' => 'fvalue1', 'field2' => 'fvalue2'))->values(array('fvalue11', 'fvalue22')); //2.2.3 Duplicate Key Update模式 //需要注意dupFields和dupValues的关联性,弱耦合 $insert->enableDuplicate(true); //开启自动Dup更新模式 //insert into test set field1='fvalue1', field2='fvalue2' on duplicate key update field1='newfvalue1', num=num+1 ; $insert->fields(array('field1', 'field2'))->dupFields(array('field1', 'num'))->values(array('fvalue1', 'fvalue2'), array('field2' => 'newfvalue1', array('plain' => 'num=num+1')));