# Where 条件 使用数据库无时无刻都需要条件去检索数据 . 框架内置的where 采用数组方式传入解析. 并还原SQL语句进行执行 ~~~ <?php namespace Action; use HY\Action; class Index extends Action { public function Index(){ //实例User表为对象 $User = M("User"); //满足email = a 的数据,并返回 user_name 字段数组 $User->select("user_name", array( "email" => "a" )); // WHERE email = 'a' $User->select(user_name", array( "user_id" => 200 )); // WHERE user_id = 200 $User->select("user_name", array( "user_id[>]" => 200 )); // WHERE user_id > 200 $User->select("user_name", array( "user_id[>=]" => 200 )); // WHERE user_id >= 200 $User->select(user_name", array( "user_id[!]" => 200 )); // WHERE user_id != 200 $User->select("user_name", array( "age[<>]" => [200, 500] )); // WHERE age BETWEEN 200 AND 500 $User->select("user_name", array( "age[><]" => [200, 500] )); // WHERE age NOT BETWEEN 200 AND 500 // [><] 和 [<>] 可以用于 datetime $User->select("user_name", array( "birthday[><]" => array( date("Y-m-d", mktime(0, 0, 0, 1, 1, 2015)), date("Y-m-d") ) )); //WHERE "create_date" BETWEEN '2015-01-01' AND '2015-05-01' (now) // 你不仅可以使用字符串和数字,还可以使用数组 $User->select("user_name", array( "OR" => array( "user_id" => [2, 123, 234, 54], "email" => array("foo@bar.com", "cat@dog.com", "admin@medoo.in") ) )); // WHERE // user_id IN (2,123,234,54) OR // email IN ('foo@bar.com','cat@dog.com','admin@medoo.in') // 多条件查询 $User->select("user_name", array( "AND" => array( "user_name[!]" => "foo", "user_id[!]" => 1024, "email[!]" => ["foo@bar.com", "cat@dog.com", "admin@medoo.in"], "city[!]" => null, "promoted[!]" => true ) )); // WHERE // `user_name` != 'foo' AND // `user_id` != 1024 AND // `email` NOT IN ('foo@bar.com','cat@dog.com','admin@medoo.in') AND // `city` IS NOT NULL // `promoted` != 1 // 或者嵌套 select() ak get() 方法 $User->select("user_name", array( "user_id" => $User->select("post", "user_id", ["comments[>]" => 40]) )); // WHERE user_id IN (2, 51, 321, 3431) } } ~~~