SQL語法:
'INSERT INTO `表格名` (`username`,`password`) VALUES ('admin','123456');
前面鍵名要用`` 後面值要用''
2.'UPDATE `表格名` SET `username`=:'admin',`password`=:'123456' WHERE 條件;
同理,前面鍵名要用``,後面值要用'', 但更新內容 鍵名 與 值 一起封裝
3.'DELETE FROM `表格名` WHERE 條件;
4.'SELECT (目標) FROM `表格名` WHERE 條件;
实例
<?php /** * Created by beebb. * Date: 25/7/2019 * Time: 9:57 */ require __DIR__ . '/db/connect.php'; //create SQL statement and prepare Obj $preObj = $pdo->prepare('INSERT INTO `userdetail` SET `username`=:username, `password`=:password,`user_id`=:user_id'); //execute SQL $preObj->execute(['username'=>'user1','password'=>'000000','user_id'=>'666']); echo '成功的添加' . $preObj->rowCount(). '条记录, 主键:'. $pdo->lastInsertId();
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /** * Created by beebb. * Date: 25/7/2019 * Time: 9:57 */ require __DIR__ . '/db/connect.php'; //create SQL statement and prepare Obj $preObj = $pdo->prepare('UPDATE `userdetail` SET `username`=:username, `password`=:password,`user_id`=:user_id'); //execute SQL $preObj->execute(['username'=>'user1','password'=>'000000','user_id'=>'666']); echo '成功的添加' . $preObj->rowCount(). '条记录, 主键:'. $pdo->lastInsertId();
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /** * Created by beebb. * Date: 25/7/2019 * Time: 9:57 */ require __DIR__ . '/db/connect.php'; //create SQL statement and prepare Obj $preObj = $pdo->prepare('SELECT * FROM `userdetail` WHERE `user_id`=:user_id'); //execute SQL $preObj->execute(['user_id'=>'666']); $datas = $preObj->fetchAll(PDO::FETCH_ASSOC); foreach ($datas as $data) { echo '<pre>' . print_r($data, true); }
运行实例 »
点击 "运行实例" 按钮查看在线实例