Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default 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

  2. #2
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default 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)) {

  3. #3
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Connecting to a second database

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

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Problem connecting to Database
    By PGO2010 in forum General Questions
    Replies: 11
    Last Post: 10 Sep 2012, 09:19 PM
  2. Problem Connecting To Database
    By jeffnord in forum General Questions
    Replies: 8
    Last Post: 28 Oct 2009, 10:48 PM
  3. Connecting to database
    By Lmichael in forum Installing on a Linux/Unix Server
    Replies: 2
    Last Post: 10 Feb 2008, 06:41 PM
  4. reconnecting to Database after connecting to PhpBB database.
    By rainthebat in forum General Questions
    Replies: 0
    Last Post: 6 Feb 2008, 09:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg