I have started investigating alternatives to my project and a few questions came out that I couldn't answer by myself.

The problem is: I want to create a web page able to access multiple Magento instances installed on the same server. Currently, I have one Magento instance per client and this project will access several Magento instances to export reports from each one (for example).

The alternatives I thought til this moment are:

  • Have another Magento instance, create a new module within it that changes its 'database target' before triggering operations/queries;

Questions until this moment:

  • Can I 'change the database target' of a Magento instance?
  • How can I access data from a Magento instance without appeal to SOAP/REST?
  • I want to re-use some components (grids, tabs, forms..) from Magento, that's why I'm not considering an independent project (Zend, for instance) that can access this code from another project. Does it make sense?
  • Any other idea?


Thanks by the tips and sorry by my ignorance. The comments let me believe that I'm able to execute something like this:

// File myScript.php
require '/home/DOMAIN1/app/Mage.php';
// get some products from DOMAIN1

require '/home/DOMAIN2/app/Mage.php';
// get some products from DOMAIN2

Is it right? Can I execute require twice (and override things from first require)?

2 Answers 2


You can create one php script at root folder of your project (Eg. script.php) and add below code to access magento instances:


error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);

/**Here you can add your code to access magento instances**/

To change connection runtime you can use below steps:

Open Magento/app/etc/config.xml add your database configuration in it.


    <host>< ![CDATA[hostname]]></host>
    <username>< ![CDATA[username]]></username>
    <password>< ![CDATA[password]]></password>
    <dbname>< ![CDATA[wordpress]]></dbname>
    <initstatements>SET NAMES utf8</initstatements>

You can access wordpress databse in above script like:

$read = Mage::getSingleton('core/resource')->getConnection('wp_read');
$write = Mage::getSingleton('core/resource')->getConnection('wp_write');

You can review from here: http://blog.decryptweb.com/connect-database-magento/

  • Nice addition with the extra connections. But you can't really set one of those as the default connection during runtime right? OP wants to use several Mage instances which would effectively require you to replace the current default connection. Commented Oct 18, 2013 at 9:04
  • Ya true sander, we can't set one of those connection as default one. To connect with different database, very nice explanation given here: fishpig.co.uk/magento/tutorials/… Commented Oct 18, 2013 at 10:12

If they're on the same server and you have access to SSH it shouldn't be to hard to set this up. Actually I did this before with a little help from my webhosting company

Make sure all the Mage installations and your platform are in the same Linux user group, set permissions of the files up in a way that the group also has read/write(/execute) permissions.

Now you can go ahead and include the Magento Core like you normally would

require /home/domain(1|2|3|...).com/www/app/Mage.php

This will give you access to that specific core. The only catch is that this will work for just one core per time, including multiple cores into one script will result in an endless supply of errors.

I did some poking around in the core but it doesn't look like you can swap different Database connections at runtime so actually connecting to different Magento installation databases is gonna take a lot of customisation I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.