PHP code to use different database


I have written a new shipping calculator and its integrated with cs-cart. My calculator uses some information from the database and I would prefer to have this in a separate database and not inside the cs-cart database.

Does anyone know of a function that cs-cart uses to do this? I can see some functions in /core/fn.database.php. Currently I am doing this to switch to the database I need.

db_connect_to ('main', 'shipping');

And before I return from my shipping calculator I do this:


If I don't do the latter, there is understandably trouble.

Ok, so this works, but is it too version reliant? I am guessing possibly. I am no mysql export, but is this inefficient for MYSQL to switch database like this. Or should I just bite the bullet and put the shipping tables in the cs-cart database.

Any thoughts?

why not just use different table names? No reason to have it in a separate DB. Cs-cart is geared toward a single DB connection within the core.

yep, I ended up doing this… I was trying to keep the shipping data separate, but there is probably no need to. I did try having it in a separate database and used the core functions as I originally described, but it stability issues…

Try http://docs.cs-cart…ional-databases


db_initiate('localhost', 'xxx', 'xxx', 'second_database', 'second', 'cscart_');
$products_array = db_get_array("second#SELECT * FROM products WHERE product_id > ?i", 130);

I hope that helps,