2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
40 * Description: This file generates the appropriate manager for the database
42 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
43 * All Rights Reserved.
44 * Contributor(s): ______________________________________..
45 ********************************************************************************/
47 require_once('include/database/DBManager.php');
49 class DBManagerFactory
52 * Returns a reference to the DB object for instance $instanceName, or the default
53 * instance if one is not specified
55 * @param string $instanceName optional, name of the instance
56 * @return object DBManager instance
58 public static function getInstance(
62 global $sugar_config, $dbinstances;
63 static $count, $old_count;
66 $config = $sugar_config['dbconfig'];
67 if(!isset($dbinstances)){
68 $dbinstances = array();
70 //fall back to the default instance name
71 if(empty($sugar_config['db'][$instanceName])){
74 if(!isset($dbinstances[$instanceName])){
75 $my_db_manager = 'MysqlManager';
76 if( $config['db_type'] == "mysql" ) {
77 if ((!isset($sugar_config['mysqli_disabled'])
78 || $sugar_config['mysqli_disabled'] == false)
79 && function_exists('mysqli_connect')) {
80 $my_db_manager = 'MysqliManager';
83 if( $config['db_type'] == "oci8" ){
85 elseif( $config['db_type'] == "mssql" ){
86 if ( function_exists('sqlsrv_connect')
87 && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'sqlsrv' ))
88 $my_db_manager = 'SqlsrvManager';
90 && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'freetds' ))
91 $my_db_manager = 'FreeTDSManager';
93 $my_db_manager = 'MssqlManager';
95 $GLOBALS['log']->info("using $my_db_manager DBManager backend");
96 if(!empty($config['db_manager'])){
97 $my_db_manager = $config['db_manager'];
100 require_once("include/database/{$my_db_manager}.php");
101 $dbinstances[$instanceName] = new $my_db_manager();
102 $dbinstances[$instanceName]->getHelper();
103 $dbinstances[$instanceName]->connect($config, true);
104 $dbinstances[$instanceName]->count_id = $count;
105 $dbinstances[$instanceName]->references = 0;
106 $dbinstances[$instanceName]->getHelper()->db = $dbinstances[$instanceName];
110 $dbinstances[$instanceName]->references = $old_count;
112 return $dbinstances[$instanceName];
116 * Returns an instance of the helper class
119 * @return object DBHelper instance
121 public static function getHelperInstance()
123 $GLOBALS['log']->info('call to DBManagerFactory::getHelperInstance() is deprecated');
124 return self::getInstance()->getHelper();
128 * Loads the DBManager and DBHelper instance class files
131 * @param string $class_name
133 public static function load_db_manager_class(
137 $GLOBALS['log']->info('call to DBManagerFactory::load_db_manager_class() is deprecated');
138 if( is_file("include/database/{$class_name}.php") && !class_exists($class_name))
139 require_once("include/database/{$class_name}.php");
141 $class_name = str_ireplace('Manager','Helper',$class_name);
143 if( is_file("include/database/{$class_name}.php") && !class_exists($class_name))
144 require_once("include/database/{$class_name}.php");