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: , ,

Posts linking to this article:

[web] 連結分享
php. parallel processes in php; beautiful code; more beautiful code; the one-line web framework; getting started with memcached; simple doctrine model to mysql script; 用php 實現http 身份驗證; 透明模拟php5.3中的“迟静态绑定(late static ...

Subscribe with Google Reader