Aproveitando o assunto ...


     Meu problema é o seguinte:

     Tenho um método no meu MODEL, onde:
     1) Através da conexão default, crio um novo banco de dados (o
nome do banco de dados é passado dinâmicamente para o meu método);
     2) Atribuo privilégios para um usuário, que também é recebido
pelo método do meu MODEL.
     3) Preciso criar (com os parâmetros recebidos pelo método)  uma
nova conexão  na classe DATABASE_CONFIG, ou pelo menos passar os
parâmetros de conexão (host, login, password, database);
     4)  Tornar essa conexão default; ou setá-la em  $this-
>useDbConfig;
     5)  Executar instruções no banco de dados, através dessa
conexão.

      Enfim, é isso.

      Obrigado.

      Paulo.

On 8 fev, 16:56, Corie <[EMAIL PROTECTED]> wrote:
> Oh, nevermind. I just reread. I guess I was simply trying to set up
> the if else inside thedatabase_configclass and set the $default
> accordingly.
>
> On Feb 8, 1:37 pm, Corie <[EMAIL PROTECTED]> wrote:
>
>
>
> > That actually does look like a better solution, as I was also trying
> > to figure out how to make it switch for all Models.
>
> > I'm a bit new to OOP, how do you set up your /config/database.php
> > file? You have to put the conditionals in a function right?
>
> > On Feb 8, 11:32 am, grigri <[EMAIL PROTECTED]> wrote:
>
> > > Interesting... I do it a completely different way. I have 2 database
> > > config files : database.dev.php and database.live.php, each containing
> > > a fullDATABASE_CONFIGclass with my configurations (default, test,
> > > and whatever else I need for the app).
>
> > > Then, in /config/database.php, I have this:
>
> > > if (empty($_SERVER['SERVER_NAME']) ||
> > > in_array(strtolower($_SERVER["SERVER_NAME"]), array('grigri',
> > > 'localhost'))) {
> > >   require "./database.dev.php";}
>
> > > else {
> > >   require "./database.live.php";
>
> > > }
>
> > > This way the models don't have to make any changes, it's all
> > > automatic.
>
> > > How do other people deal with this?
>
> > > On Feb 8, 4:23 pm, Corie <[EMAIL PROTECTED]> wrote:
>
> > > > I'm running the same cake app on two different servers, development
> > > > and production. I want to change the database config that's used
> > > > depending on the server. I've got the following set up now.
>
> > > > /config/database.php
>
> > > > classDATABASE_CONFIG{
> > > >         var $development = array(
> > > >                 'driver' => 'mysql',
> > > >                 'persistent' => false,
> > > >                 'host' => 'localhost',
> > > >                 'port' => '',
> > > >                 'login' => 'admin',
> > > >                 'password' => 'password',
> > > >                 'database' => 'db',
> > > >                 'schema' => '',
> > > >                 'prefix' => '',
> > > >                 'encoding' => ''
> > > >         );
> > > >         var $production = array(
> > > >                 'driver' => 'mysql',
> > > >                 'persistent' => false,
> > > >                 'host' => 'localhost',
> > > >                 'port' => '',
> > > >                 'login' => 'user_admin',
> > > >                 'password' => 'password',
> > > >                 'database' => 'user_db',
> > > >                 'schema' => '',
> > > >                 'prefix' => '',
> > > >                 'encoding' => ''
> > > >         );
>
> > > > }
>
> > > > /models/table.php
>
> > > > class Table extends AppModel
> > > > {
> > > >         var $name = 'Table';
>
> > > >         function beforeFind()
> > > >         {
> > > >                 if(is_dir('D:\webserver\private_html\site'))
> > > >                 {
> > > >                         $this->useDbConfig = 'development';
> > > >                 }
> > > >                 elseif(is_dir(DS.'home'.DS.'user'.DS.'public_html'))
> > > >                 {
> > > >                         $this->useDbConfig = 'production';
> > > >                 }
> > > >         }
>
> > > > }
>
> > > > It just keeps trying to use the 'default' config. I've also tested my
> > > > logic by just putting $this->useDbConfig = 'development'; directly
> > > > under the beforeFind() function, but it still does nothing. Do I need
> > > > to put this somewhere else?- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to