Tuesday, December 14, 2010

Get the Auto_increment value of a Table in MySQL

SELECT auto_increment 
FROM information_schema.tables 
WHERE table_name='the_table_you_want';

Sunday, December 12, 2010

Get the MySQL Configuration Parameters from databases.yml

MySQL configuration is stored in config/databases.yml. Use the code below to get the parameters in an action.
$databaseConf = sfYaml::load(sfConfig::get('sf_config_dir') . '/databases.yml');
$params   = $databaseConf ['all']['doctrine']['param'];
$dsn      = $params['dsn'];
$username = $params['username'];
$password = $params['password'];
$database = substr($dsn, strpos($dsn, 'dbname=')+7);
Only works if your dns parameter does not contain anything after the database's name, ex: dsn: mysql:host=localhost;dbname=thenameofthedatabase