added db::first method.

This commit is contained in:
Taylor Otwell 2011-07-26 22:16:55 -05:00
parent 066db38ddb
commit 0f1bd8a739
1 changed files with 14 additions and 1 deletions

View File

@ -33,6 +33,19 @@ public static function connection($connection = null)
return static::$connections[$connection];
}
/**
* Execute a SQL query against the connection and return the first result.
*
* @param string $sql
* @param array $bindings
* @param string $connection
* @return object
*/
public static function first($sql, $bindings = array(), $connection = null)
{
return (count($results = static::query($sql, $bindings, $connection)) > 0) ? $results[0] : null;
}
/**
* Execute a SQL query against the connection.
*
@ -46,7 +59,7 @@ public static function connection($connection = null)
* @param string $sql
* @param array $bindings
* @param string $connection
* @return mixed
* @return array
*/
public static function query($sql, $bindings = array(), $connection = null)
{