TYPO3 API  SVNRelease
FakeDbConnection.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2009 Xavier Perseguers <typo3@perseguers.ch>
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *
00017  *  This script is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU General Public License for more details.
00021  *
00022  *  This copyright notice MUST APPEAR in all copies of the script!
00023  ***************************************************************/
00024 
00025 
00026 /**
00027  * Fake ADOdb connection factory.
00028  *
00029  * $Id: FakeDbConnection.php 40716 2010-12-01 10:49:27Z xperseguers $
00030  *
00031  * @author Xavier Perseguers <typo3@perseguers.ch>
00032  *
00033  * @package TYPO3
00034  * @subpackage dbal
00035  */
00036 class FakeDbConnection {
00037 
00038     /**
00039      * Creates a fake database connection.
00040      *
00041      * @param ux_t3lib_db $db
00042      * @param string $databaseType Type of the database (e.g., 'oracle')
00043      * @param string $driver Driver to use (e.g., 'oci8')
00044      * @return ADOConnection
00045      */
00046     public static function connect(ux_t3lib_db $db, $driver) {
00047         // Make sure to have a clean configuration
00048         $db->clearCachedFieldInfo();
00049         $db->_call('initInternalVariables');
00050 
00051         include_once(t3lib_extMgm::extPath('adodb') . 'adodb/drivers/adodb-' . $driver . '.inc.php');
00052 
00053         $handlerKey = '_DEFAULT';
00054         $db->lastHandlerKey = $handlerKey;
00055         $db->handlerInstance[$handlerKey] = t3lib_div::makeInstance('ADODB_' . $driver);
00056 
00057         // From method handler_init()
00058         $db->handlerInstance[$handlerKey]->DataDictionary = NewDataDictionary($db->handlerInstance[$handlerKey]);
00059 
00060         // DataDictionary being set, a connectionID may be arbitrarily chosen
00061         $db->handlerInstance[$handlerKey]->_connectionID = rand(1, 1000);
00062     }
00063 
00064 }
00065 
00066 ?>