Zen Cart Logo
Forums / General Questions / Connecting to a second database

Connecting to a second database

Views: 683

Results 1 to 3 of 3
5 Mar 2013, 8:57 PM
#1
strelitzia avatar

strelitzia

Totally Zenned

Join Date:
Nov 2005
Location:
France
Posts:
588
Plugin Contributions:
1

Connecting to a second database

Hi,

I'm trying to get my cart to connect to a second db hosted on the same server as the original zc db.

I see that the db connection is referenced in includes/functions/sessions.php, includes/init_includes/init_database.php and admin/includes/init_includes/init_database.php.

I tried changing:

$db->connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE, USE_PCONNECT, false);

to:

$db->connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE, USE_PCONNECT, false);
$db2->connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE2, USE_PCONNECT, true);

after adding a define for DB_DATABASE2 to the configure.php files, but i get an error in the logs that says:

Call to a member function connect() on a non-object in /usr/local/zend/apache2/htdocs/devsites/newsite/newadmin/includes/init_includes/init_database.php on line 21

Does anyone know the best method of opening two db connections at the same time?

Thanks

5 Mar 2013, 9:09 PM
#2
strelitzia avatar

strelitzia

Totally Zenned

Join Date:
Nov 2005
Location:
France
Posts:
588
Plugin Contributions:
1

Re: Connecting to a second database

Update on error logs:

Accessing admin,
Call to a member function connect() on a non-object in /usr/local/zend/apache2/htdocs/devsites/newsite/newadmin/includes/init_includes/init_database.php on line 21

Accessing the page in the shop that wants a connection to the second db,
Call to a member function connect() on a non-object in /usr/local/zend/apache2/htdocs/devsites/newsite/includes/functions/sessions.php on line 57
Call to a member function Execute() on a non-object in /usr/local/zend/apache2/htdocs/devsites/newsite/includes/templates/template_default/templates/tpl_product_info_display.php on line 65

No errors are recorded in the log going to index.php, or any other page in the shop.

store init_database.php line 23 was changed to:
if (!$db->connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE, USE_PCONNECT, false) AND $db2->connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE2, USE_PCONNECT, true)) {

5 Mar 2013, 10:41 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Connecting to a second database

You can't use the $db2 variable until you've first declared it.