I use below code to bootstrap Magento in an external script, which works. As an example it gets the name of a specific product.

Is it possible to connect to another Magento database (on the same server) from such a script? If yes, how would I do this? I tried several things but didn't got a working end result.


require_once '../app/Mage.php';

$sku = 'product X';
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);


1 Answer 1


This is achievable. You need to define database credentials in your local.xml where you have your script placed. You can have something like below:

enter image description here

Once you have some create a module / model to connect to second database and play around it to achieve what you want.

  • Thanks. I just want to use Magento default models. For example get a product with 'catalog/product' model from the second database. How would I do that? Can you give an example?
    – Akif
    Sep 5, 2018 at 21:41

Your Answer

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

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