• Yii框架1版本数据操作-直接数据库


     1 ==================查询==================
     2 $data = Yii::app()->db->createCommand('select * from admin where id between 1 and 10')->query();//执行一个非查询的sql语句
     3 $data = Yii::app()->db->createCommand('select * from admin where id between 1 and 10')->queryAll();//返回多行数据
     4 $data = Yii::app()->db->createCommand('select * from admin where id between 1 and 10')->queryRow();//返回一行数据
     5 $data = Yii::app()->db->createCommand('select id from admin where id between 1 and 10')->queryColumn();//返回多个指定字段的值
     6 $data = Yii::app()->db->createCommand('select id from admin where id between 1 and 10')->queryScalar();//返回一个指定字段的值
     7 
     8 ==================新增==================
     9 $insert = Yii::app()->db->createCommand()->insert('admin', ['id' => 1, 'name' => '你好']);
    10 $insertId = Yii::app()->db->getLastInsertID();//获取插入数据的主键ID
    11 $insert = Yii::app()->db->createCommand()->batchInsert('admin', ['id', 'name'], [1, '你好'], [2, '你好'], [3, '你好']);
    12 
    13 ==================修改==================
    14 $update = Yii::app()->db->createCommand()->update('admin', ['name' => '你好呀'], 'id = 1');//修改admin表,id = 1 name的值为'你好呀',set name = '你好呀' where id = 1
    15 
    16 ==================删除==================
    17 $delete = Yii::app()->db->createCommand()->delete('admin', 'id = 1');//删除admin表id = 1的数据
  • 相关阅读:
    软件工程结对作业02
    软件工程个人作业04
    第五周学习进度条
    软件工程中的形式化方法
    需求工程
    软件过程
    软件项目管理
    软件概论概述
    人月神话读后略有感想
    软件工程—理论、方法和实践 第一章:概述
  • 原文地址:https://www.cnblogs.com/firstlady/p/11384403.html
Copyright © 2020-2023  润新知