...
Code Block | ||
---|---|---|
| ||
// Produces SELECT * FROM `clients` WHERE `user_id`='15' OR `id_code`='USR15' $this->Record->select()->from("clients")->where("user_id", "=", 15)->orWhere("id_code", "=", "USR15"); |
Where In
Code Block | ||
---|---|---|
| ||
// Produces SELECT * FROM `clients` WHERE `id` IN ('1','2','3','4')
$this->Record->select()->from("clients")->where("id", "in", array(1,2,3,4)); |
Like
Code Block | ||
---|---|---|
| ||
// Produces SELECT * FROM `clients` WHERE `id_code` LIKE 'USR15' $this->Record->select()->from("clients")->like("id_code", "USR15"); // Produces SELECT * FROM `clients` WHERE `id_code` LIKE '%USR15%' $this->Record->select()->from("clients")->like("id_code", "%USR15%"); |
...
Code Block | ||
---|---|---|
| ||
// Produces SELECT * FROM `clients` WHERE ((`id_code` LIKE '%USR15%' OR `id_code` LIKE '%USR18%') AND `name` LIKE 'Firstname%')
$this->Record->select()->from("clients")->
open()->
open()->
like("id_code", "%USR15%")->
orLike("id_code", "%USR18%")->
close()->
like("name", "Firstname%")->
close(); |
Joins
Inner Join
Code Block | ||
---|---|---|
| ||
// Produces SELECT `clients`.* FROM `clients` INNER JOIN `contacts` ON `contacts`.`user_id`=`clients`.`user_id` $this->Record->select(array("clients.*"))->from("clients")->innerJoin("contacts", "contacts.user_id", "=", "clients.user_id", false); |
Left Join
Code Block | ||
---|---|---|
| ||
// Produces SELECT `clients`.* FROM `clients` LEFT JOIN `contacts` ON `contacts`.`user_id`=`clients`.`user_id`
$this->Record->select(array("clients.*"))->from("clients")->leftJoin("contacts", "contacts.user_id", "=", "clients.user_id", false); |
Right Join
Code Block | ||
---|---|---|
| ||
// Produces SELECT `clients`.* FROM `clients` right JOIN `contacts` ON `contacts`.`user_id`=`clients`.`user_id`
$this->Record->select(array("clients.*"))->from("clients")->rightJoin("contacts", "contacts.user_id", "=", "clients.user_id", false); |
Cross Join
Code Block | ||
---|---|---|
| ||
// Produces SELECT `clients`.* FROM `clients`, `contacts`
$this->Record->select(array("clients.*"))->from("clients")->from("contacts"); |
Multiple conditions
Code Block | ||
---|---|---|
| ||
// Produces SELECT `clients`.* FROM `clients` LEFT JOIN `contacts` ON `contacts`.`user_id`=`clients`.`user_id` AND `contacts`.`id`!='0'
$this->Record->select(array("clients.*"))->from("clients")->on("contacts.id", "!=", 0)->leftJoin("contacts", "contacts.user_id", "=", "clients.user_id", false);
// Produces SELECT `clients`.* FROM `clients` LEFT JOIN `contacts` ON `contacts`.`user_id`=`clients`.`user_id` OR `contacts`.`id`!='0'
$this->Record->select(array("clients.*"))->from("clients")->orOn("contacts.id", "!=", 0)->leftJoin("contacts", "contacts.user_id", "=", "clients.user_id", false); |
Insert
Update
Delete
Table Management
...