$Model->query("select * from think_user where score >= " . $score); $Model->Table('think_user user')->where($where)->select();

D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\Controller\UserController.class.php

    //http://localhost/thinkphp323/index.php/home/User/query_score/score/20
    public function query_score($score=60){    
        $Model = new \Think\Model(); // 实例化一个model对象 没有对应任何数据表
        $ret = $Model->query("select * from think_user where score >= " . $score);
        var_dump($ret);
    }
    
    //http://localhost/thinkphp323/index.php/home/User/insert_user?username=lily&score=60
    public function insert_user($username,$score=60){
        $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
        $ret=$Model->execute("insert into think_user(username,score) values('{$username}',{$score})");
        var_dump($ret);
    }
    
    //http://localhost/thinkphp323/index.php/home/User/delete_user?username=lily
    public function delete_user($username){
        $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
        $ret=$Model->execute("delete from think_user where username='{$username}'");
        var_dump($ret);
    }

    //http://localhost/thinkphp323/index.php/home/User/update_user?username=lily&score=60
    public function update_user($username,$score=60){
        $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
        $ret=$Model->execute("update think_user set score={$score} where username='{$username}'");
        var_dump($ret);
    }
    
    
    //http://localhost/thinkphp323/index.php/home/User/where_order_limit?where=&order=&limit=
    //http://localhost/thinkphp323/index.php/home/User/where_order_limit?where=username like '%m'&order=username&limit=3
    //http://localhost/thinkphp323/index.php/home/User/where_order_limit?where=username like '%l%'&order=username&limit=3
    public function where_order_limit($where,$order,$limit){
        $User = M("User"); // 实例化User对象
        echo "User->where($where)->order($order)->limit($limit)->select()",'<hr>';
        $ret=$User->where($where)->order($order)->limit((int)$limit)->select();
        var_dump($ret);
           echo "User->order($order)->limit($limit)->where($where)->select()",'<hr>';
        $ret=$User->order($order)->limit((int)$limit)->where($where)->select();
        var_dump($ret); 
    }
    
    //http://localhost/thinkphp323/index.php/home/User/table_where_select
    public function table_where_select($where=null){
        if($where==null){
            $this->display();
        }else{        
            $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
            $ret=$Model->Table('think_user user')->where($where)->select();
            var_dump($ret);
        }
    }

D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\View\User\table_where_select.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta charset="UTF-8">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>

<FORM method="get" action="">
where:<INPUT type="text" name="where" ><br>
<INPUT type="submit" value="get提交">
</FORM>

<FORM method="post" action="">
where:<INPUT type="text" name="where" ><br>
<INPUT type="submit" value="post提交">
</FORM>

 </body>
</html>

 

    //http://localhost/thinkphp323/index.php/home/User/table_where_select
    public function table_where_select($where=null){
        if($where==null){
            $this->display();
        }else{        
            $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
            $ret=$Model->Table('think_user user')->where($where)->select();
            var_dump($ret);
            
            $ret=$Model->Table('mantis.mantis_test_table')->where($where)->select();
            var_dump($ret);
        }
    }

 

posted @ 2017-12-01 10:55  sky20080101  阅读(85)  评论(0)    收藏  举报