Thanks Andy, I appreciate it.
I do have one issue along these lines though. I'm trying to set up a database connection to a different database on a different server using the classes provided in Sugar already (I currently have a separate class to connect to a different db but would like to simplify it and keep the classes the same). To set up multiple $dbinstances I changed DBManager getInstance to look for the configuration based on the instance name:
PHP Code:
if(empty($instanceName)) $instanceName = 'db';
$config = $sugar_config[$instanceName.'config'];
This works for creating another connection and the new connection does work properly but the old 'db' instance for Sugar get's screwed up a bit. It's DBHelper object has the new connection's DBManager object instead of it's own. Here's the $dbinstances array after adding a second database instance:
PHP Code:
Array ( [db] => MssqlManager Object ( [dbType] => mssql
[helper] => MssqlHelper Object ( [db] => MssqlManager Object ( [dbType] => mssql
[helper] => MssqlHelper Object *RECURSION*
[tableName] => [database] =>Resource id #297
[dieOnError] => [encode] => 1 [query_time] => 0 [lastmysqlrow] => -1 [last_error] => [lastResult] => Array ( ) [count_id] => [references] => 0 ) [bean] => )
[tableName] => [database] => Resource id #152
[dieOnError] => [encode] => 1 [query_time] => 0.007982 [lastmysqlrow] => -1 [last_error] => [lastResult] => Array ( ) [count_id] => [references] => 37 [lastsql] => SELECT contacts.* , contacts_cstm.* FROM contacts LEFT JOIN contacts_cstm ON contacts.id = contacts_cstm.id_c WHERE contacts.id = '37ec27ad-052c-fd27-26d6-4397652e3bd1' )
[cpu] => MssqlManager Object ( [dbType] => mssql
[helper] => MssqlHelper Object ( [db] => MssqlManager Object *RECURSION* [bean] => )
[tableName] => [database] => Resource id #297 [dieOnError] => [encode] => 1 [query_time] => 0 [lastmysqlrow] => -1 [last_error] => [lastResult] => Array ( ) [count_id] => [references] => 0 ) )
cpu is the 2nd database instance. Resource id #152 is for the Sugar db and Resource #297 is the Cpu db. You can see in the array above that #297 is in the MssqlHelperObject for the Sugar db instance. Any ideas to get this object to not get overwritten?
Thanks,
Jason
Bookmarks