标签:
通过GET方式获取网页&id的数值
// $request = \yii::$app->request;
// $id=$request->get(‘id‘);
// dd($id);
// $data = [
// ‘userName‘ => "wqpeixun.com",
// ‘ip‘ => 1270101,
// ‘arr‘ =>[
// ‘age‘ => 1,
// ‘class‘ => ‘1班‘
// ],
//// ];
// $user = [
// ‘userName‘ => ‘小兵老师‘,
// ‘age‘ => 28,
// ];
// $article = [
// ‘title‘ => ‘phpstorm真好用呀!‘,
// ];
// $data=[
// ‘user‘=>$user,
// ‘article‘=>$article,
// ];
//// $data = compact(‘user‘, ‘article‘);
// $data = [
// ‘str‘ => ‘wew<script>alert (11);</script>‘,
// ];
// 通过原生SQL语句获取数据
// $request=\yii::$app->request;
// $id=$request->get(‘id‘);
// $sql = "select * from article where id=:id";
// $data=[
// ‘id‘=>$id,
// ];
// $row = article::findBySql($sql,$data)->all();
// dd($row);
// 通过原生SQL语句删除和修改//
// Yii::$app->db->createCommand(‘UPDATE article SET num=101 WHERE id=40‘)->execute();
// $data = \Yii::$app->db->createCommand(‘UPDATE article SET num=103 WHERE id=:id‘,[‘:id‘=>40])->execute();
//
// //通过函数获取全部数据
// $data=article::find()->all();
//带where条件语句
// id=4
// $where=[
// ‘id‘=>4,
// ];
// $data=article::find()->where($where)->all();
// id>3
// $where=[
// ‘>‘,
// ‘id‘,
// 2
// ];
// $data=article::find()->where($where)->all();
// 5<=id<=2
// $where=[
// ‘between‘,
// ‘id‘,
// 2,
// 5,
// ];
// $data=article::find()->where($where)->all();
//// like title 习大大
// $where=[
// ‘like‘,
// ‘title‘,
// ‘习大大‘
// ];
// $data=article::find()->where($where)->all();
// 查询单条数据id=1
// $where=[
// ‘id‘=>1,
// ];
//// $data=article::find()->where($where)->one();
// $data=article::findOne(1);
//查询3,4,5条记录
// $where=[
// 3,4,5,
// ];
// $data=article::findAll($where);
// //插入记录
// $article = new article();
// $article->title = ‘432432‘;
// $article->num=8;
// $data = $article->save();
// //插入记录后获取新增的记录ID号码
// $id=$article->attributes[‘id‘];
// 删除单条记录
// $article=article::findOne(14);
// $data=$article->delete();
// $article=article::find()->where([‘id‘=>13])->one();
// $data=$article->delete();
// $article=article::find()->where([‘id‘=>12])->all();
// $data=$article[0]->delete();
// $where = [
// ‘id=:id‘,
// [‘:id‘ => 27]
// ];
// //dd($where);
// $data = article::deleteAll($where[0], $where[1]);
//删除多条数据
//Customer::deleteAll(‘age > :age AND gender = :gender‘, [‘:age‘ => 20, ‘:gender‘ => ‘M‘]);
// $data = article::deleteAll(‘id>:id and num>=:num‘, [‘:id‘ => 32,‘:num‘=>6]);
// 删除多条记录数据
// $where=[
// ‘id>=:id and title like :title and num>:num‘,
// [‘:id‘=>32,‘:title‘=>‘窗口1‘,‘:num‘=>100]
// ];
// $data=article::deleteAll($where[0],$where[1]);
//修改单条记录
// $article=article::findOne(40);
// $article->title="窗口3232";
// $data=$article->save();
//修改多条记录
// $data = article::updateAll([‘title‘ => ‘窗口2211‘, ‘num‘ => ‘200‘], ‘num>=:num and title=:title‘, [‘:num‘ => 100, ‘:title‘ => ‘窗口1‘]);
标签:
原文地址:http://www.cnblogs.com/xiangqc/p/5872551.html