MysqliDb::getValue PHP Method

getValue() public method

A convenient SELECT COLUMN function to get a single column value from one row
public getValue ( string $tableName, string $column, integer $limit = 1 ) : mixed
$tableName string The name of the database table to work with.
$column string The desired column
$limit integer Limit of rows to select. Use null for unlimited..1 by default
return mixed Contains the value of a returned column / array of values
    public function getValue($tableName, $column, $limit = 1)
    {
        $res = $this->ArrayBuilder()->get($tableName, $limit, "{$column} AS retval");
        if (!$res) {
            return null;
        }
        if ($limit == 1) {
            if (isset($res[0]["retval"])) {
                return $res[0]["retval"];
            }
            return null;
        }
        $newRes = array();
        for ($i = 0; $i < $this->count; $i++) {
            $newRes[] = $res[$i]['retval'];
        }
        return $newRes;
    }

Usage Example

コード例 #1
0
ファイル: dbObject.php プロジェクト: TwistItLabs/website
 /**
  * Function to get a total records count
  *
  * @return int
  */
 private function count()
 {
     $res = $this->db->getValue($this->dbTable, "count(*)");
     return $res['cnt'];
 }
All Usage Examples Of MysqliDb::getValue