diff -rupN a/includes/database.mysql.inc b/includes/database.mysql.inc
--- a/includes/database.mysql.inc	2013-01-18 00:27:02.000000000 +0100
+++ b/includes/database.mysql.inc	2013-02-13 12:31:57.000000000 +0100
@@ -177,13 +177,15 @@ function _db_query($query, $debug = 0, $
  *
  * @param $result
  *   A database query result resource, as returned from db_query().
+ * @param $class_name
+ *   Class name to type-cast the DB row to.
  * @return
  *   An object representing the next row of the result, or FALSE. The attributes
  *   of this object are the table fields selected by the query.
  */
-function db_fetch_object($result) {
+function db_fetch_object($result, $class_name = NULL) {
   if ($result) {
-    return mysql_fetch_object($result);
+    return mysql_fetch_object($result, $class_name);
   }
 }
 
diff -rupN a/includes/database.mysqli.inc b/includes/database.mysqli.inc
--- a/includes/database.mysqli.inc	2013-01-18 00:27:02.000000000 +0100
+++ b/includes/database.mysqli.inc	2013-02-13 12:34:48.000000000 +0100
@@ -176,13 +176,15 @@ function _db_query($query, $debug = 0, $
  *
  * @param $result
  *   A database query result resource, as returned from db_query().
+ * @param $class_name
+ *   Class name to type-cast the DB row to.
  * @return
  *   An object representing the next row of the result, or FALSE. The attributes
  *   of this object are the table fields selected by the query.
  */
-function db_fetch_object($result) {
+function db_fetch_object($result, $class_name = NULL) {
   if ($result) {
-    $object = mysqli_fetch_object($result);
+    $object = mysqli_fetch_object($result, $class_name);
     return isset($object) ? $object : FALSE;
   }
 }
@@ -336,7 +338,7 @@ function db_query_range_slave($query) {
  *
  * Use this as a substitute for db_query() when the results need to be stored
  * in a temporary table.
- * 
+ *
  * User-supplied arguments to the query should be passed in as separate parameters
  * so that they can be properly escaped to avoid SQL injection attacks.
  *
diff -rupN a/includes/database.pgsql.inc b/includes/database.pgsql.inc
--- a/includes/database.pgsql.inc	2013-01-18 00:27:02.000000000 +0100
+++ b/includes/database.pgsql.inc	2013-02-13 12:33:18.000000000 +0100
@@ -179,13 +179,15 @@ function _db_query($query, $debug = 0, $
  *
  * @param $result
  *   A database query result resource, as returned from db_query().
+ * @param $class_name
+ *   Class name to type-cast the DB row to.
  * @return
  *   An object representing the next row of the result, or FALSE. The attributes
  *   of this object are the table fields selected by the query.
  */
-function db_fetch_object($result) {
+function db_fetch_object($result, $class_name = NULL) {
   if ($result) {
-    return pg_fetch_object($result);
+    return pg_fetch_object($result, NULL, $class_name);
   }
 }
 
