--- /dev/null
+<?php
+/**
+ * Copyright 2011 The Horde Project (http://www.horde.org/)
+ *
+ * @author Jan Schneider <jan@horde.org>
+ * @license http://opensource.org/licenses/bsd-license.php
+ * @category Horde
+ * @package Db
+ */
+
+/**
+ * @author Jan Schneider <jan@horde.org>
+ * @license http://opensource.org/licenses/bsd-license.php
+ * @category Horde
+ * @package Db
+ */
+class Horde_Db
+{
+ /**
+ * Specifies that the fetch method shall return each row as an array
+ * indexed by column name as returned in the corresponding result set.
+ */
+ const FETCH_ASSOC = 2;
+
+ /**
+ * Specifies that the fetch method shall return each row as an array
+ * indexed by column number as returned in the corresponding result set,
+ * starting at column 0.
+ */
+ const FETCH_NUM = 3;
+
+ /**
+ * Specifies that the fetch method shall return each row as an array
+ * indexed by both column name and number as returned in the corresponding
+ * result set, starting at column 0.
+ */
+ const FETCH_BOTH = 4;
+}
protected $_eof;
/**
+ * Which kind of keys to use for results.
+ */
+ protected $_fetchMode = MYSQL_ASSOC;
+
+ /**
* Constructor
*
* @param Horde_Db_Adapter $adapter
}
if ($this->_result) {
- $row = mysql_fetch_array($this->_result, MYSQL_BOTH);
+ $row = mysql_fetch_array($this->_result, $this->_fetchMode);
if (!$row) {
$this->_eof = true;
} else {
}
/**
- * Return the current row and advance the recordset one row.
+ * Returns the current row and advances the recordset one row.
+ *
+ * @param integer $fetchmode The default fetch mode for this result. One
+ * of the Horde_Db::FETCH_* constants.
*/
- public function fetch()
+ public function fetch($fetchmode = Horde_Db::FETCH_ASSOC)
{
if (!$this->valid()) {
return null;
}
+ $this->setFetchMode($fetchmode);
$row = $this->current();
$this->next();
return $row;
return !$this->_eof;
}
+ /**
+ * Sets the default fetch mode for this result.
+ *
+ * @param integer $fetchmode One of the Horde_Db::FETCH_* constants.
+ */
+ public function setFetchMode($fetchmode)
+ {
+ $map = array(Horde_Db::FETCH_ASSOC => MYSQL_ASSOC,
+ Horde_Db::FETCH_NUM => MYSQL_NUM,
+ Horde_Db::FETCH_BOTH => MYSQL_BOTH);
+ $this->_fetchMode = $map[$fetchmode];
+ }
}
protected $_eof;
/**
+ * Which kind of keys to use for results.
+ */
+ protected $_fetchMode = MYSQLI_ASSOC;
+
+ /**
* Constructor
*
* @param Horde_Db_Adapter $adapter
}
if ($this->_result) {
- $row = $this->_result->fetch_array(MYSQLI_ASSOC);
+ $row = $this->_result->fetch_array($this->_fetchMode);
if (!$row) {
$this->_eof = true;
} else {
}
/**
- * Return the current row and advance the recordset one row.
+ * Returns the current row and advances the recordset one row.
+ *
+ * @param integer $fetchmode The default fetch mode for this result. One
+ * of the Horde_Db::FETCH_* constants.
*/
- public function fetch()
+ public function fetch($fetchmode = Horde_Db::FETCH_ASSOC)
{
if (!$this->valid()) {
return null;
}
+ $this->setFetchMode($fetchmode);
$row = $this->current();
$this->next();
return $row;
return !$this->_eof;
}
+ /**
+ * Sets the default fetch mode for this result.
+ *
+ * @param integer $fetchmode One of the Horde_Db::FETCH_* constants.
+ */
+ public function setFetchMode($fetchmode)
+ {
+ $map = array(Horde_Db::FETCH_ASSOC => MYSQL_ASSOC,
+ Horde_Db::FETCH_NUM => MYSQL_NUM,
+ Horde_Db::FETCH_BOTH => MYSQL_BOTH);
+ $this->_fetchMode = $map[$fetchmode];
+ }
}
<email>chuck@horde.org</email>
<active>yes</active>
</lead>
- <date>2010-10-22</date>
- <time>09:45:53</time>
+ <date>2011-02-01</date>
+ <time>15:51:20</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
</notes>
<contents>
<dir baseinstalldir="/" name="/">
+ <dir name="bin">
+ <file name="horde-db-migrate" role="script" />
+ </dir> <!-- /bin -->
<dir name="doc">
<file name="README.TESTING.txt" role="doc" />
<file name="TODO.txt" role="doc" />
<file name="Exception.php" role="php" />
<file name="StatementParser.php" role="php" />
</dir> <!-- /lib/Horde/Db -->
+ <file name="Db.php" role="php" />
</dir> <!-- /lib/Horde -->
</dir> <!-- /lib -->
<dir name="test">
</dependencies>
<phprelease>
<filelist>
+ <install as="horde-db-migrate" name="bin/horde-db-migrate" />
<install as="README.TESTING.txt" name="doc/README.TESTING.txt" />
<install as="TODO.txt" name="doc/TODO.txt" />
+ <install as="Horde/Db.php" name="lib/Horde/Db.php" />
<install as="Horde/Db/Adapter.php" name="lib/Horde/Db/Adapter.php" />
<install as="Horde/Db/Exception.php" name="lib/Horde/Db/Exception.php" />
<install as="Horde/Db/StatementParser.php" name="lib/Horde/Db/StatementParser.php" />
<release>beta</release>
<api>beta</api>
</stability>
- <date>2010-10-22</date>
+ <date>2011-02-01</date>
<license uri="http://opensource.org/licenses/bsd-license.php">BSD</license>
<notes>
* Add support for adding autoincrement to a column.