Commit 179cde2d authored by Alexander Butenko's avatar Alexander Butenko

Added getValue function

parent 9b62b349
...@@ -283,6 +283,23 @@ class MysqliDb ...@@ -283,6 +283,23 @@ class MysqliDb
return null; return null;
} }
/**
* A convenient SELECT * function to get one value.
*
* @param string $tableName The name of the database table to work with.
*
* @return array Contains the returned column from the select query.
*/
public function getValue($tableName, $column)
{
$res = $this->get ($tableName, 1, "{$column} as retval");
if (isset($res[0]["retval"]))
return $res[0]["retval"];
return null;
}
/** /**
* *
* @param <string $tableName The name of the table. * @param <string $tableName The name of the table.
......
...@@ -121,6 +121,13 @@ $stats = $db->getOne ("users", "sum(id), count(*) as cnt"); ...@@ -121,6 +121,13 @@ $stats = $db->getOne ("users", "sum(id), count(*) as cnt");
echo "total ".$stats['cnt']. "users found"; echo "total ".$stats['cnt']. "users found";
``` ```
or select one column or function result
```php
$count = getValue ("users", "count(*)");
echo "{$count} users found";
```
### Delete Query ### Delete Query
```php ```php
$db->where('id', 1); $db->where('id', 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment