數據庫原生sql寫法(返回值為影響行數)
//執行數據庫操作
$res = db()->execute($sql);
1.查詢操作
Db::query('select * from user where id<=? and id>=?',[8,5]);
//?為占位符,8和5為對應參數
Db::query('select * from user where id=:id',['id'=>8]);
例:
$id = 1;
$data = Db::query("select * from user where id =?",[$id]);
2.寫入操作
Db::execute('insert into user (id, name) value (?, ?)',[2,'zhangsan']);
Db::execute('insert into user (id,name) value (:id, :name)',['id'=>2,'name'=>'zhangsan']);
3.修改
Db::execute("update user set age='20' where id=9");
4.刪除
Db::execute("delete from user where id=20");
Db::execute("delete from user where id>?",[20]);
Db::execute("delete from user where id=:id",['id'=>20]);
//打印出執行的sql語句(打印出最后一條sql語句)
echo Db::getLastSql();
- 空白目錄
- 關于頁面跳轉跟重定向
- thinkphp5return的問題
- thinkphp5權限auth
- thinkphp5關聯查詢多表查詢join
- javascript
- 數據庫命令行操作
- php間隔一段時間自動執行
- PHP字符串首尾留N位,中間替換成*號
- tp5獲取當前域名
- PHP常用函數
- 注冊發送短信驗證的接口詳解
- php可逆加密解密
- 配置本地虛擬主機
- thinkphp5跨控制器調用
- thinkphp5框架加載流程
- thinkphp5路由詳解
- thinkphp5功能集合
- thinkphp5數據庫操作
- delete,put類型
- tp5數據庫查詢
- tp5數據庫增刪改
- 事務機制
- thinkphp模型model新建和查詢
- tp5model的新增
- tp5model修改
- tp5model刪除和軟刪除
- tp5視圖
- tp5API