YII1.1框架数据库增删改查

        //查询一行数据
        $user = Yii::app()->db->createCommand()
            ->select('uid,username')
            ->from('table_user')
            ->where('username=:username',array(':username' => '张三'))
            ->queryRow();
       //查询多行数据
        $user = Yii::app()->db->createCommand()
            ->select('uid,username')
            ->from('table_user')
            ->queryAll();
        //修改操作
        Yii::app()->db->createCommand()->update(
            'table_user',
            array('name' => 'zhangsan','address'=>'beijing'),
            'email=:email',
            array(':email' => email)
            );
        //增加数据
        Yii::app()->db->createCommand()->insert('table_user',   
        	array('username' => 'zhangsan','
       	 	email' => '[email protected]'
        )); 
        //删除数据
        Yii::app()->db->createCommand()->delete(
        	'table_user', 'id=:id',   
            array(':id' => 2)
        ); 
        //批量插入多行
        $count = count($arr);
        for ($i =0; $i < $count; $i++){
            $arr[$i]['tid'] = $tid;
        }
        Yii::app()->db->schema->commandBuilder
            ->createMultipleInsertCommand('table_user', $arr)
            ->execute();

你可能感兴趣的:(PHP框架)