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:
Questions until this moment:
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'; Mage::app('default'); // get some products from DOMAIN1 require '/home/DOMAIN2/app/Mage.php'; Mage::app('default'); // get some products from DOMAIN2
Is it right? Can I execute require twice (and override things from first require)?
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 Mage::app('default');
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.
You can create one php script at root folder of your project (Eg. script.php) and add below code to access magento instances:
<?php error_reporting(E_ALL | E_STRICT); define('MAGENTO_ROOT', getcwd()); $mageFilename = MAGENTO_ROOT . '/app/Mage.php'; require_once $mageFilename; Mage::setIsDeveloperMode(true); ini_set('display_errors', 1); umask(0); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); /**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.
<wp_setup> <connection> <host>< ![CDATA[hostname]]></host> <username>< ![CDATA[username]]></username> <password>< ![CDATA[password]]></password> <dbname>< ![CDATA[wordpress]]></dbname> <model>mysql4</model> <initstatements>SET NAMES utf8</initstatements> <type>pdo_mysql</type> <active>1</active> </connection> </wp_setup> <wp_write> <connection> <use>wp_setup</use> </connection> </wp_write> <wp_read> <connection> <use>wp_setup</use> </connection> </wp_read>
You can access wordpress databse in above script like:
<?php $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/