You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
or select with custom columns set. Functions also could be used
76
96
77
97
```php
78
-
$stats = $db->getOne ("users", "sum(id), count(*) as cnt");
79
-
echo "total ".$stats['cnt']. "users found";
80
-
81
-
$cols = Array ("id, name, email");
98
+
$cols = Array ("id", "name", "email");
82
99
$users = $db->get ("users", null, $cols);
83
100
if ($db->count > 0)
84
101
foreach ($users as $user) {
@@ -92,6 +109,9 @@ or select just one row
92
109
$db->where ("id", 1);
93
110
$user = $db->getOne ("users");
94
111
echo $user['id'];
112
+
113
+
$stats = $db->getOne ("users", "sum(id), count(*) as cnt");
114
+
echo "total ".$stats['cnt']. "users found";
95
115
```
96
116
97
117
### Delete Query
@@ -122,28 +142,38 @@ print_r($results); // contains Array of returned rows
122
142
123
143
124
144
### Where Method
125
-
This method allows you to specify the parameters of the query.
145
+
This method allows you to specify where parameters of the query.
146
+
WARNING: In order to use column to column comparisons only raw where conditions should be used as column name or functions cant be passed as a bind variable.
126
147
127
-
Regular == operator:
148
+
Regular == operator with variables:
128
149
```php
129
-
$db->where('id', 1);
130
-
$db->where('login', 'admin');
131
-
$results = $db->get('users');
150
+
$db->where('id', 1);
151
+
$db->where('login', 'admin');
152
+
$results = $db->get('users');
132
153
// Gives: SELECT * FROM users WHERE id=1 AND login='admin';
133
154
```
134
155
156
+
Regular == operator with column to column comparison:
135
157
```php
136
-
$db->where('id', 50, ">=");
137
-
// or $db->where('id', Array('>=' => 50));
158
+
// WRONG
159
+
$db->where ('lastLogin', 'createdAt');
160
+
// CORRECT
161
+
$db->where ('lastLogin = createdAt');
162
+
$results = $db->get ('users');
163
+
// Gives: SELECT * FROM users WHERE lastLogin = createdAt;
164
+
```
138
165
139
-
$results = $db->get('users');
166
+
```php
167
+
$db->where ('id', 50, ">=");
168
+
// or $db->where ('id', Array ('>=' => 50));
169
+
$results = $db->get ('users');
140
170
// Gives: SELECT * FROM users WHERE id >= 50;
141
171
```
142
172
143
173
BETWEEN / NOT BETWEEN:
144
174
```php
145
-
$db->where('id', Array(4, 20), 'between');
146
-
// or $db->where('id', Array('between' => Array(4, 20) ) );
175
+
$db->where('id', Array(4, 20), 'BETWEEN');
176
+
// or $db->where('id', Array ('BETWEEN' => Array(4, 20)));
147
177
148
178
$results = $db->get('users');
149
179
// Gives: SELECT * FROM users WHERE id BETWEEN 4 AND 20
0 commit comments