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
Copy file name to clipboardExpand all lines: readme.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,6 +187,18 @@ or select one column value or function result
187
187
$count = $db->getValue ("users", "count(*)");
188
188
echo "{$count} users found";
189
189
```
190
+
191
+
select one column value or function result from multiple rows:
192
+
``php
193
+
$logins = $db->getValue ("users", "login", null);
194
+
// select login from users
195
+
$logins = $db->getValue ("users", "login", 5);
196
+
// select login from users limit 5
197
+
foreach ($logins as $login)
198
+
echo $login;
199
+
```
200
+
201
+
190
202
### Defining a return type
191
203
MysqliDb can return result in 3 different formats: Array of Array, Array of Objects and a Json string. To select a return type use ArrayBuilder(), ObjectBuilder() and JsonBuilder() methods. Note that ArrayBuilder() is a default return type
192
204
```php
@@ -207,6 +219,28 @@ foreach ($users as $user) {
207
219
print_r ($user);
208
220
}
209
221
```
222
+
To avoid long if checks there are couple helper functions to work with raw query select results:
223
+
224
+
Get 1 row of results:
225
+
```php
226
+
$user = $db->rawQueryOne ('select * from users where id=?', Array(10));
227
+
echo $user['login'];
228
+
// Object return type
229
+
$user = $db->ObjectBuilder()->rawQueryOne ('select * from users where id=?', Array(10));
230
+
echo $user->login;
231
+
```
232
+
Get 1 column value as a string:
233
+
```php
234
+
$password = $db->rawQueryValue ('select password from users where id=? limit 1', Array(10));
235
+
echo "Password is {$password}";
236
+
NOTE: for a rawQueryValue() to return string instead of an array 'limit 1' should be added to the end of the query.
237
+
```
238
+
Get 1 column value from multiple rows:
239
+
```php
240
+
$logins = $db->rawQueryValue ('select login from users limit 10');
0 commit comments