php接收⽤户输⼊和对数据库得增删改查public function test()
{
$id=$_GET["id"];
return$id;
}
public function get(){
// 获取⼀个值,如果没有就获取第⼆个作为默认值
// laravel中echo只能输出字符串
echo Input::get("id","10086");
}
public function all(){
/
/ 获取所有参数
$all = Input::all();
// dump+die
dd($all);
}
public function has(){
// 判断id是否存在
$has = Input::has("id");
if ($has){
echo "存在";
} else{
echo "不存在";
}
}
public function except(){
// 获取除了指定参数之外得值
dd(Input::except(["id"]));
}
public function only(){
// 获取指定参数,返回数组
dd(Input::only(["name"]));
}
/
**
* 获取⽤户输⼊,可以接受post也可以接受get
*/
public function getParam(){
// 获取所有⽤户输⼊
$all1 = Input::all();
// 获取单个⽤户输⼊
$get1 = Input::get("name");
// 获取指定⼏个⽤户输⼊
$only = Input::only(["name"]);
// 判断输⼊得某个值是否存在
$has = Input::has("name");
}
public function add(){
$table = DB::table("test1");
// ⼆维数组批量插⼊,⼀位数组单条添加
$result = $table -> insert([
[
'name' => '马冬梅',
'age' => 16,
'address' => '地址',
'sex' => '⼥'
]
,
[
php修改数据库内容'name' => '马冬梅1',
'age' => 16,
'address' => '地址',
'sex' => '⼥'
]]
);
// 插⼊⼀条数据并返回id
$result = $table -> insertGetId(
[
'name' => '马冬梅21',
'age' => 16,
'address' => '地址',
'sex' => '⼥'
]
);
dd($result);
}
public function del(){
DB::table("test1")->where("id","=","1")->delete();
}
public function select1(){
// ⼿写sql
$all = DB::select("select name,age from test1");
dd($all);
}
public function opration(){
// ⼿写增删改sql
DB::statement("insert into test1 (name,age) values('胡琪',223)");
}
public function update(){
// 修改test1表中id等于1得name为张三风
$table = DB::table("test1");
$result = $table -> where("id","=","1") -> update([
"name"=>"张三丰"
]);
// 每次加1
DB::table("test1")->increment("age");
// 每次加5
DB::table("test1")->increment("age",5);
return$result;
}
public function select(){
/
/ 查询test1表中所有得数据
$all = DB::table("test1")->get();
// 循环打印
foreach ($all as$key => $value){
echo "id是:{$value -> id} name是{$value -> name}";
}
// where条件查询。and之间⽤->where->where
// or之间⽤->orWhere()->orWhere()
$get = DB::table("test1")->where("id","=","1")->get();
// 获取与之匹配得第⼀条
$one = DB::table("test1")->where("id","=","1")->first();
dd($one);
// 获取指定得⼀个字段
$value1 = DB::table("test1")->where("id","=","1")->value("name");
dd ($value1);
//获取指定列
$values = DB::table("test1")->select("name","age")->get();
return$values;
// orderBy得使⽤
$values = DB::table("test1")->select("name","age")->orderBy("age","desc")->get();
return$values;
// 跳过前两条显⽰两条
$values1 = DB::table("test1")->select("name","age")->limit(2)->offset(2)->get();
return$values1;
}
2.给导包起别名(config包中app.php得aliasess)