Blogger Information
Blog 37
fans 0
comment 1
visits 29648
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
laravel连接数据库操作增删查改-2019-11-06
H先生
Original
792 people have browsed it

1.更新管理员登录帐号email

实例

<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class Dbtest extends Controller
{
    public function index(){
    /*{
        $res = DB::table('admin')->get()->all();
        foreach ($res as $item){
            echo $item->id.'-'.$item->email.'<br>';
        }
        echo '<pre>';
        print_r($res);*/

    // 更新
       $res = DB::update('update admin set email="无缝" where id=1');
       var_dump($res);
    }
}
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


1.png



2.添加管理员帐号


实例

<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class Dbtest extends Controller
{
    public function index(){
    /*{
        $res = DB::table('admin')->get()->all();
        foreach ($res as $item){
            echo $item->id.'-'.$item->email.'<br>';
        }
        echo '<pre>';
        print_r($res);*/

    // 更新
    //   $res = DB::update('update admin set email="无缝1" where id=?',[1]);

    // 添加
        $res = DB::insert('insert admin(`email`,`psword`)values("xiaomao@qq.com","12345")');
       var_dump($res);
    }
}
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


1.png


3.删除一个管理员帐号


实例

<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class Dbtest extends Controller
{
    public function index(){
    /*{
        $res = DB::table('admin')->get()->all();
        foreach ($res as $item){
            echo $item->id.'-'.$item->email.'<br>';
        }
        echo '<pre>';
        print_r($res);*/

    // 更新
    //   $res = DB::update('update admin set email="无缝1" where id=?',[1]);

    // 添加
    //    $res = DB::insert('insert admin(`email`,`psword`)values("xiaomao@qq.com","12345")');

    // 删除
        $res = DB::delete('delete from admin where id=:uid',['uid'=>2]);
        var_dump($res);
    }
}
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


1.png



4.查询管理员帐号



实例

<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class Dbtest extends Controller
{
    public function index(){
    /*{
        $res = DB::table('admin')->get()->all();
        foreach ($res as $item){
            echo $item->id.'-'.$item->email.'<br>';
        }
        echo '<pre>';
        print_r($res);*/

    // 更新
    //   $res = DB::update('update admin set email="无缝1" where id=?',[1]);

    // 添加
    //    $res = DB::insert('insert admin(`email`,`psword`)values("xiaomao@qq.com","12345")');

    // 删除
    //    $res = DB::delete('delete from admin where id=:uid',['uid'=>2]);

    // 查询
          $res = DB::select('select * from admin');

        print_r($res);
    }
}
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


1.png



















































Correction status:qualified

Teacher's comments:写得不错, 继续
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post