Results 1 to 5 of 5
  1. #1
    Join Date
    May 2006
    Posts
    6
    Plugin Contributions
    0

    Default Connect to Additional Database?

    Hello,

    I've added zen cart in a subfolder to an already created site that has a CMS system. I need to add some links at the top of the Zen Cart store that are auto-generated from another database, i.e. the CMS system of the mother site. When I connect to the other database in zen cart, zen cart breaks down apparently not being able to connect to its database after I connect to mine. I've changed my connection Constants to make sure they are not the same as the ones Zen Cart uses, but apparently that's not the problem.

    Is it possible to connect to an additional database from within Zen Cart? I've simply added the connection to the top of "tpl_main_page.php".

    Thanks for your help.

    Glen

  2. #2
    Join Date
    May 2006
    Posts
    6
    Plugin Contributions
    0

    Default Re: Connect to Additional Database?

    For anyone else wondering. I figured this out after doing some searching:

    After opening a connection to a second database the easiest thing to do is to use:

    mysql_select_db('database_name');

    to select the database you want to use. In the case of Zen Cart after connecting to my db, doing what I want and then ending I just reconnect to the Zen Cart db.

    For Example:

    mysql_connect(my database);

    my code to get stuff from my database;

    mysql_select_db('zen_cart_db_name');

    If I need my db again I just use a similar format.

    mysql_select_db('my_database');

    my code to get stuff from my database;

    mysql_select_db('zen_cart_db_name');

    Just have to remember to always reselect the zen cart db after doing what I need to do.

    Hope this helps someone else trying to do this.

    Glen

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

    Default Re: Connect to Additional Database?

    If you're going to do raw mysql_xxxxx function calls, then yes, that's how you'll have to do it.

    If you use Zen Cart's db abstraction layer, you can create another db connection perhaps called $db1, and use that for queries instead. That way $db and $db1 point to separate connections. See the init_includes/init_database.php for an example of creating a db connection.
    .

    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.

  4. #4
    Join Date
    May 2006
    Posts
    6
    Plugin Contributions
    0

    Default Re: Connect to Additional Database?

    A little beyond my skill level, but something I can probably figure out. Thanks for the reply.

  5. #5

    Default Re: Connect to Additional Database?

    This looks interesting, I would like to try this out to connect to the forum database to pull new post info onto my front page.

 

 

Similar Threads

  1. Can't connect to my database.
    By misty16 in forum General Questions
    Replies: 32
    Last Post: 13 Oct 2010, 05:10 PM
  2. Cannot connect to database
    By Decostyle in forum General Questions
    Replies: 2
    Last Post: 7 Oct 2008, 08:40 PM
  3. re connect to Database.
    By rainthebat in forum General Questions
    Replies: 3
    Last Post: 4 Sep 2008, 08:48 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