1 回答

TA貢獻1900條經驗 獲得超5個贊
原生SQL查詢有 query() 和 execute() 兩個方法:
query():用于 SQL 查詢操作,并返回符合查詢條件的數據集
execute():更新和寫入數據的 SQL 操作,返回影響的記錄數
public function read(){ // 實例化一個空模型,沒有對應任何數據表 $Dao = M(); //或者使用 $Dao = new Model(); $list = $Dao->query("select * from user where uid<5"); if($list){ $this->assign('list', $list ); $this->display(); } else { $this->error($Dao->getError()); }}
public function read(){ header("Content-Type:text/html; charset=utf-8"); // 實例化一個空模型,沒有對應任何數據表 $Dao = M(); //或者使用 $Dao = new Model(); $num = $Dao->execute("update user set email = '[email protected]' where uid=3"); if($num){ echo '更新 ',$num,' 條記錄。'; }else{ echo '無記錄更新'; }}
- 1 回答
- 0 關注
- 1279 瀏覽
添加回答
舉報