0

Short version: Is it possible to create a database from a setup script?

Long version: I've set-up a module that creates it's own database resource connection for storing information in a database independent of the main Magento install. I've also got the migration scripts set-up to generate the tables. Is it possible using this migration script to attempt to create the database if it doesn't exist?

I've tried playing around a little, but as soon as I call startSetup, I get a database not found exception. I can't actually find where the dbname actually get's used. I can see it get's passed into the constructor when the adapter get's created, but couldn't seem to find where it's used.

1 Answer 1

0

Well I seem to have found a passable solution.

// first use the main database connection to create the external database
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query('CREATE DATABASE IF NOT EXISTS external_db_name');

// then call startSetup, which will now be able to connect to the external database
// and allow us to create our tables
$installer = $this;
$installer->startSetup();

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.