From 0f1bd8a739996e2594cd32334a3d22b8d9a48a50 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 22:16:55 -0500 Subject: [PATCH] added db::first method. --- system/db.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/system/db.php b/system/db.php index 4769fc74..e2765f61 100644 --- a/system/db.php +++ b/system/db.php @@ -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) {