Add columnCount() to native mysql drivers.
authorJan Schneider <jan@horde.org>
Tue, 1 Feb 2011 15:10:34 +0000 (16:10 +0100)
committerJan Schneider <jan@horde.org>
Tue, 1 Feb 2011 15:10:34 +0000 (16:10 +0100)
framework/Db/lib/Horde/Db/Adapter/Mysql/Result.php
framework/Db/lib/Horde/Db/Adapter/Mysqli/Result.php

index 8735891..7141d86 100644 (file)
@@ -214,4 +214,17 @@ class Horde_Db_Adapter_Mysql_Result implements Iterator
                      Horde_Db::FETCH_BOTH  => MYSQL_BOTH);
         $this->_fetchMode = $map[$fetchmode];
     }
+
+    /**
+     * Returns the number of columns in the result set
+     *
+     * @return integer  Number of columns.
+     */
+    public function columnCount()
+    {
+        if (is_null($this->_result)) {
+            $this->rewind();
+        }
+        return mysql_num_fields($this->_result);
+    }
 }
index 9318bb2..40c5e33 100644 (file)
@@ -214,4 +214,17 @@ class Horde_Db_Adapter_Mysqli_Result implements Iterator
                      Horde_Db::FETCH_BOTH  => MYSQL_BOTH);
         $this->_fetchMode = $map[$fetchmode];
     }
+
+    /**
+     * Returns the number of columns in the result set
+     *
+     * @return integer  Number of columns.
+     */
+    public function columnCount()
+    {
+        if (is_null($this->_result)) {
+            $this->rewind();
+        }
+        return $this->_result->field_count;
+    }
 }