1 回答

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊
原生SQL查詢有 query() 和 execute() 兩個(gè)方法:
query():用于 SQL 查詢操作,并返回符合查詢條件的數(shù)據(jù)集
execute():更新和寫入數(shù)據(jù)的 SQL 操作,返回影響的記錄數(shù)
public function read(){ // 實(shí)例化一個(gè)空模型,沒(méi)有對(duì)應(yīng)任何數(shù)據(jù)表 $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"); // 實(shí)例化一個(gè)空模型,沒(méi)有對(duì)應(yīng)任何數(shù)據(jù)表 $Dao = M(); //或者使用 $Dao = new Model(); $num = $Dao->execute("update user set email = '12345@xxx.com' where uid=3"); if($num){ echo '更新 ',$num,' 條記錄。'; }else{ echo '無(wú)記錄更新'; }}
- 1 回答
- 0 關(guān)注
- 1291 瀏覽
添加回答
舉報(bào)