亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

預(yù)處理操作crud

原創(chuàng) 2019-03-16 10:06:11 396
摘要:<?php  class Curd { public $pdo = ''; public function __construct(){ $this->pdo = new PDO('mysql:host=127.0.0.1;dbname=1604a','root','root'); } public

<?php 

class Curd

{

public $pdo = '';


public function __construct(){

$this->pdo = new PDO('mysql:host=127.0.0.1;dbname=1604a','root','root');

}

public function show(){//此方法為展示方法

$sql = "SELECT * FROM `userl` where user_id > :user_id";

$sie = $this->pdo->prepare($sql);

$sie->execute([':user_id'=>1]);

$aaa[] = '';

    while ($row =$sie->fetch(PDO::FETCH_ASSOC)) {

    $aaa[] = $row;

    }

var_dump($aaa);

}

public function a(){

echo '你沒有傳遞方法名所以被迫跳到此頁面';

}

//add()//此為添加方法

public function add(){

$sql = 'INSERT INTO `userl` (`name`, `password`, `state`, `creationTime`) VALUES (:name, :password,:state ,:creationTime)';

$sie = $this->pdo->prepare($sql);

$name = '王大大';

$password = '12333123';

$state = 0;

$creationTime = '2019-03-15 14:13:52';

$sie->bindParam(':name', $name, PDO::PARAM_STR,100);

$sie->bindParam(':password', $password, PDO::PARAM_STR,100);

$sie->bindParam(':state', $state, PDO::PARAM_INT);

$sie->bindParam(':creationTime', $creationTime, PDO::PARAM_STR,100);

if ($sie->execute()) {

echo ($sie->rowCount()>0)?'當(dāng)前添加了'.$sie->rowCount().'條記錄':'沒有添加記錄';

}else{

exit($sie->errorInfo());

}

}

public function upl(){//此方法為修改方法

$sql = 'UPDATE `userl` SET `name`=:name, `password`=:password, `state`=:state, `creationTime`= :creationTime WHERE `user_id`=:user_id';

$sie = $this->pdo->prepare($sql);


$user_id = 2;

$name = '王小曉';

$password = '123331';

$state = 0;

$creationTime = '2019-03-15 14:13:52';

//參數(shù)綁定


$sie->bindParam(':user_id',$user_id,PDO::PARAM_INT);

$sie->bindParam(':name', $name, PDO::PARAM_STR,100);

$sie->bindParam(':password', $password, PDO::PARAM_STR,100);

$sie->bindParam(':state', $state, PDO::PARAM_INT);

$sie->bindParam(':creationTime', $creationTime, PDO::PARAM_STR,100);


if ($sie->execute()) {

echo ($sie->rowCount()>0)?'當(dāng)前有'.$sie->rowCount().'條記錄被修改':'沒有記錄被修改';

}else{

exit($sie->errorInfo());

}

}

public function del(){//此方法為刪除方法

$sql = 'DELETE FROM `userl` WHERE (`user_id`=:user_id)';

$sie = $this->pdo->prepare($sql);

//參數(shù)綁定

$user_id = 1;

$sie->bindParam(':user_id',$user_id,PDO::PARAM_INT);

if ($sie->execute()) {

echo ($sie->rowCount()>0)?'當(dāng)前有'.$sie->rowCount().'條記錄被刪除':'沒有記錄被刪除';

}else{

exit($sie->errorInfo());

}

}

}

$curd = new Curd();

$r = isset($_GET['r'])?$_GET['r']:'a';

$curd->$r();


批改老師:查無此人批改時間:2019-03-16 10:44:55
老師總結(jié):寫的不錯?,F(xiàn)在數(shù)據(jù)庫操作,都使用pdo了,所以要多練習(xí),繼續(xù)加油。

發(fā)佈手記

熱門詞條