Source for file MDB2.php
Documentation is available at MDB2.php
declare(encoding = "utf-8");
* This file is part of ForwardFW a web application framework.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @subpackage Controller/DataHandler
* @author Alexander Opitz <opitz.alexander@primacom.net>
* @copyright 2009-2010 The Authors
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link http://forwardfw.sourceforge.net
* @since File available since Release 0.0.7
require_once 'ForwardFW/Exception/DataHandler.php';
require_once 'ForwardFW/Controller/DataHandler.php';
require_once 'ForwardFW/Interface/Application.php';
require_once 'PEAR/MDB2.php';
* Managing DataLoading via PEAR::MDB2
* @subpackage Controller/DataHandler
* @author Alexander Opitz <opitz.alexander@primacom.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link http://forwardfw.sourceforge.net
* @var array Prefix for tables
* Loads Data from a connection (DB, SOAP, File)
* @param string $strConnection Name of connection
* @param array $arOptions Options to load the data
* @return mixed Data from the connection.
public function loadFrom($strConnection, array $arOptions)
$conMDB2 = $this->getConnection($strConnection);
$strQuery = 'SELECT ' . $arOptions['select'] . ' FROM ';
. '_' . $arOptions['from'] . '`';
$strQuery .= '`' . $arOptions['from'] . '`';
if (isset ($arOptions['where'])) {
$strQuery .= ' WHERE ' . $arOptions['where'];
if (isset ($arOptions['group'])) {
$strQuery .= ' GROUP BY ' . $arOptions['group'];
if (isset ($arOptions['order'])) {
$strQuery .= ' ORDER BY ' . $arOptions['order'];
if (isset ($arOptions['limit'])) {
$strQuery .= ' LIMIT ' . $arOptions['limit'];
$resultMDB2 = $conMDB2->query($strQuery);
if (PEAR::isError($resultMDB2)) {
$this->application->getResponse()->addError($resultMDB2->getMessage() . $resultMDB2->getUserinfo());
. $resultMDB2->getMessage()
. $resultMDB2->getUserinfo()
while ($arRow = $resultMDB2->fetchRow(MDB2_FETCHMODE_ASSOC)) {
* Saves Data to a connection (DB, SOAP, File)
* @param string $strConnection Name of connection
* @param array $arOptions Options to load the data
* @return mixed Data from the connection.
public function saveTo($strConnection, array $options)
* Loads and initialize the connection handler.
* @param string $strConnection Name of connection
public function initConnection($strConnection)
if (isset ($arConfig['prefix'])) {
$options = array('portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE);
$options = array_merge($options, $arConfig['options']);
$conMDB2 = MDB2::connect($arConfig['dsn'], $options);
if (PEAR::isError($conMDB2)) {
$conMDB2->getMessage() . $conMDB2->getUserinfo()
'Cannot initialize MDB Connection: '
. $conMDB2->getUserinfo()
$ret = $conMDB2->exec('set character set utf8');
|