Elgg\Database::getDataRow PHP Method

getDataRow() public method

Similar to {@link \Elgg\Database::getData()} but returns only the first row matched. If a callback function $callback is specified, the row will be passed as the only argument to $callback.
public getDataRow ( string $query, callable $callback = null, array $params = [] ) : mixed
$query string The query to execute.
$callback callable A callback function to apply to the row
$params array Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
return mixed A single database result object or the result of the callback function.
    public function getDataRow($query, $callback = null, array $params = [])
    {
        return $this->getResults($query, $callback, true, $params);
    }

Usage Example

コード例 #1
0
 /**
  * {@inheritDoc}
  */
 public function read($session_id)
 {
     $id = sanitize_string($session_id);
     $query = "SELECT * FROM {$this->db->getTablePrefix()}users_sessions WHERE session='{$id}'";
     $result = $this->db->getDataRow($query);
     if ($result) {
         return (string) $result->data;
     } else {
         return false;
     }
 }
All Usage Examples Of Elgg\Database::getDataRow