Skip to content

Commit 179cde2

Browse files
committed
Added getValue function
1 parent 9b62b34 commit 179cde2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

MysqliDb.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,23 @@ public function getOne($tableName, $columns = '*')
283283
return null;
284284
}
285285

286+
/**
287+
* A convenient SELECT * function to get one value.
288+
*
289+
* @param string $tableName The name of the database table to work with.
290+
*
291+
* @return array Contains the returned column from the select query.
292+
*/
293+
public function getValue($tableName, $column)
294+
{
295+
$res = $this->get ($tableName, 1, "{$column} as retval");
296+
297+
if (isset($res[0]["retval"]))
298+
return $res[0]["retval"];
299+
300+
return null;
301+
}
302+
286303
/**
287304
*
288305
* @param <string $tableName The name of the table.

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ $stats = $db->getOne ("users", "sum(id), count(*) as cnt");
121121
echo "total ".$stats['cnt']. "users found";
122122
```
123123

124+
or select one column or function result
125+
126+
```php
127+
$count = getValue ("users", "count(*)");
128+
echo "{$count} users found";
129+
```
130+
124131
### Delete Query
125132
```php
126133
$db->where('id', 1);

0 commit comments

Comments
 (0)