DQL new docs, refs #181
This commit is contained in:
parent
96bf070900
commit
45e9bc8420
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
// POSITIONAL PARAMETERS:
|
||||
$users = $conn->query("FROM User WHERE User.name = ?", array('Arnold'));
|
||||
|
||||
$users = $conn->query("FROM User WHERE User.id > ? AND User.name LIKE ?", array(50, 'A%'));
|
||||
|
||||
|
||||
// NAMED PARAMETERS:
|
||||
|
||||
$users = $conn->query("FROM User WHERE User.name = :name", array(':name' => 'Arnold'));
|
||||
|
||||
$users = $conn->query("FROM User WHERE User.id > :id AND User.name LIKE :name", array(':id' => 50, ':name' => 'A%'));
|
||||
?>
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
// finding all users whose email ends with '@gmail.com'
|
||||
$users = $conn->query("FROM User u, u.Email e WHERE e.address LIKE '%@gmail.com'");
|
||||
|
||||
// finding all users whose name starts with letter 'A'
|
||||
$users = $conn->query("FROM User u WHERE u.name LIKE 'A%'");
|
||||
?>
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// finding all users which don't belong to any group 1
|
||||
$query = "FROM User WHERE User.id NOT IN
|
||||
(SELECT u.id FROM User u
|
||||
INNER JOIN u.Group g WHERE g.id = ?";
|
||||
|
||||
$users = $conn->query($query, array(1));
|
||||
|
||||
// finding all users which don't belong to any groups
|
||||
// Notice:
|
||||
// the usage of INNER JOIN
|
||||
// the usage of empty brackets preceding the Group component
|
||||
|
||||
$query = "FROM User WHERE User.id NOT IN
|
||||
(SELECT u.id FROM User u
|
||||
INNER JOIN u.Group g)";
|
||||
|
||||
$users = $conn->query($query);
|
||||
?>
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
// retrieve all users and the phonenumber count for each user
|
||||
|
||||
$users = $conn->query("SELECT u.*, COUNT(p.id) count FROM User u, u.Phonenumber p GROUP BY u.id");
|
||||
|
||||
foreach($users as $user) {
|
||||
print $user->name . ' has ' . $user->Phonenumber->getAggregateValue('count') . ' phonenumbers';
|
||||
}
|
||||
?>
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
// retrieve the first 20 users and all their associated phonenumbers
|
||||
|
||||
$users = $conn->query("SELECT u.*, p.* FROM User u, u.Phonenumber p LIMIT 20");
|
||||
|
||||
foreach($users as $user) {
|
||||
print ' --- '.$user->name.' --- \n';
|
||||
|
||||
foreach($user->Phonenumber as $p) {
|
||||
print $p->phonenumber.'\n';
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user