$u=$User->where('score=' . $score)->select();
一、使用字符串作为查询条件
这是最传统的方式,但是安全性不高,例如:
$User = M("User"); // 实例化User对象
$User->where('type=1 AND status=1')->select();
最后生成的SQL语句是
SELECT * FROM think_user WHERE type=1 AND status=1
采用字符串查询的时候,我们可以配合使用新版提供的字符串条件的安全预处理机制,暂且不再细说。
//http://localhost/thinkphp323/index.php/home/User/select_score?score=100 public function select_score($score=1){ $User = M("User"); // 实例化User对象 $u=$User->where('score=' . $score)->select(); var_dump($u); }
array (size=2) 0 => array (size=4) 'id' =>
string
'1' (length=1) 'username' =>
string
'jim' (length=3) 'score' =>
string
'100' (length=3) 'create_time' =>
string
'0' (length=1) 1 => array (size=4) 'id' =>
string
'2' (length=1) 'username' =>
string
'tom' (length=3) 'score' =>
string
'100' (length=3) 'create_time' =>
string
 '0' (length=1)

 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号