Skip to content

Conversation

@avbdr
Copy link
Collaborator

@avbdr avbdr commented Jun 9, 2014

Added optional 'operator' variable. Backwards compatibility preserved.

$db->where('id', Array(4, 20), 'between');
// or 
$db->where('id', Array('between' => Array(4, 20) ) );

Subquery in selects:

$ids = $db->subQuery ();
$ids->where ("qty", 2, ">");
$ids->get ("products", null, "userId");

$db->where ("id", $ids, 'in');
$res = $db->get ("users");
// Gives SELECT * FROM users WHERE id IN (SELECT userId FROM products WHERE qty > 2)

Subquery in inserts:

$userIdQ = $db->subQuery ();
$userIdQ->where ("id", 6);
$userIdQ->getOne ("users", "name"),

$data = Array (
    "productName" => "test product",
    "userId" => $userIdQ,
    "lastUpdated" => $db->now()
);
$id = $db->insert ("products", $data);
// Gives INSERT INTO PRODUCTS (productName, userId, lastUpdated) values ("test product", (SELECT name FROM users WHERE id = 6), NOW());

@avbdr
Copy link
Collaborator Author

avbdr commented Jun 9, 2014

also f01c82e is fixing an issue where multiple where() and orWhere() conditions were overwritting previous conditions on the same variable.

ThingEngineer added a commit that referenced this pull request Jun 26, 2014
Subquery / nicer where() api
@ThingEngineer ThingEngineer merged commit 5fdf5f2 into ThingEngineer:master Jun 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants