logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Ability to set DB name after objects have been built?: msg#00026

Subject: Re: Ability to set DB name after objects have been built?
Hi Tony,

You realize that the DATABASE_NAME has no direct relationship to the
actual name of the database, right?  The only purpose of DATABASE_NAME
is to tell Propel runtime how to find the connect params in the
runtime-conf.php (it looks for a key with the value of DATABASE_NAME). 
You can have your database named whatever you want ...

Hans

Tony Bibbs wrote:
> I've posted on this topic in the past. I have a need for the auto
> generated model objects to have their DATABASE_NAME defined at
> runtime.  That's because user's of my software can name the database
> anything.
>
> Is there any reason we couldn't simply pull this from the propel
> configuration file given to Propel::init()?
>
> I've already hacked a semi-dynamic version of the Propel configuration
> file.  Here is what I have (note that $glConf is a variable of config
> options in my application's config.php).  It works like a charm, I can
> change below at runtime except for the database name.  Is there any
> reason Propel::init() couldn't take an optional database name
> argument?  e.g.:
>
> Propel::init($myPropelConfig, $dataSourceName);
>
> Seems like a rather easy fix to a long time problem.  It would then
> only require a change to the base class generation to use that value
> instead of the class constant DATABASE_NAME.  Also apologies in
> advance if this has been addressed already and I just haven't see it
> on the list.
>
> If this hasn't been addressed yet, I'd like to discuss with Hans, et.
> al  on how to best do this and I'd be willing to write the hack myself
> since I need it badly.
>
> --Tony
>
> [below is my dynamic Propel config]
>
> global $glConf;
>
> return array (
>   'log' =>
>   array (
>     'ident' => 'propel-Geeklog-2',
>     'level' => '7',
>     'name' => $glConf['path_logs'] . 'propel.log',
>   ),
>   'propel' =>
>   array (
>     'datasources' =>
>     array (
>       $glConf['db_name'] =>
>       array (
>         'adapter' => $glConf['dbms'],
>         'connection' =>
>         array (
>           'phptype' => $glConf['dbms'],
>           'hostspec' => $glConf['db_host'],
>           'database' => $glConf['db_name'],
>           'username' => $glConf['db_user'],
>           'password' => $glConf['db_pass'],
>         ),
>       ),
>       'default' => $glConf['db_name'],
>     ),
>   ),
> );
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> users-unsubscribe-zi6esuMpPRkWBrYXtHbyV9i2O/JbrIOy@xxxxxxxxxxxxxxxx
> For additional commands, e-mail: 
> users-help-zi6esuMpPRkWBrYXtHbyV9i2O/JbrIOy@xxxxxxxxxxxxxxxx
>


<Prev in Thread] Current Thread [Next in Thread>