Simple Doctrine model to MySQL script

I’m a bit rusty, after scouring the Doctrine manual for the import functions I found a script of my own that I totally had forgotten:

require_once('../lib/doctrine/lib/Doctrine.php');
spl_autoload_register(array('Doctrine','autoload'));
require('../lib/smoc/Mdl.php');
Doctrine_Manager::getInstance()->setAttribute('model_loading', 'conservative');
Doctrine::loadModels('models');
$conn = Doctrine_Manager::connection('mysql://root:@localhost/emailer');
//Doctrine::createTablesFromArray(array('Aspect', 'Destination', 'Aspect_list'));
echo Doctrine::generateSqlFromModels('models');

Note that I’ve moved my own controller code out of the project folder and into the lib folder where it should be (in the smoc folder, some kind of play on the words Smarty and Doctrine).

So the above will output valid SQL I can just cop paste into phpMyAdmin and run. I prefer going from Model -> SQL since it’s faster and more comfortable just copy pasting PHP code than messing around in phpMyAdmin, especially when it comes to all the foreign keys and indexes when using InnoDB.


Related Posts

Tags: , ,