I am seeing the same problem in my Application (not a shell script)
I am able to temporarily fix the problem by modifying cake\cake\models
\datasources\dbo\dbo_mysql.php function _execute() with the following
code (code is commented out below to show what I added):
function _execute($sql) {
// static $dblastused;
// if ($dblastused != $this->config["database"]) {
// $this->disconnect();
// $this->connect();
// }
// $dblastused = $this->config["database"];
// print_r($this->config);
// echo"$sql<br>";
return mysql_query($sql, $this->connection);
}
basically when I had the print_r and echo statement in there I could
see that the config variable was correct, but the database connection
was still using the last database. it doesn't happen on the first
database switch but the second. i.e. DESCRIBE tablenamefromdb1;
DESCRIBE tablenamefromdb2; DESCRIBE tablename2fromdb1;
and I get the following warning:
Warning (512): SQL Error: 1146: Table 'db2.tablename2fromdb1' doesn't
exist [CORE/cake/libs/model/datasources/dbo_source.php, line 501]
So if you force the db connection to disconnect and reconnect it works
properly (I put in a check to make sure it changed before doing this
using that static variable)
NOTE!!!! I don't think this "fix" should actually be used by anybody.
It's just demonstration code to debug the problem.
Bryn
On Jun 9, 2:19 am, Guillaume <[EMAIL PROTECTED]> wrote:
> Hello,
> I don't have time to test if deeper now (going to work!) but I
> encountered strange problems with a Shell script using Models
> belonging to different databases.
> My Shell script aims at migrating data from an old database named
> "popnews_old" to a new one named "popnews" so it uses models belonging
> to different databases.
>
> $this->Model->find('all') with a Model pointing toward the old
> database issues a query to the wrong database.
>
> It used to work perfectly before.
>
> Here are some excerpts of my code :
>
> //{app}/config/database.php
> var $default = array('driver' => 'mysql',
> 'connect' =>
> 'mysql_connect',
> 'host' =>
> '127.0.0.1',
> 'login' =>
> 'xxxxxx',
> 'password' =>
> 'xxxxx',
> 'database' =>
> 'popnews',
> 'prefix' =>
> '',
> 'port' =>
> 8889);
>
> var $oldLocalDatabase = array('driver' => 'mysql',
> 'connect' =>
> 'mysql_connect',
> 'host' => '127.0.0.1',
> 'port' => 8889,
> 'login' => 'xxxxxxxx',
> 'password' => 'xxxxx',
> 'database' =>
> 'popnews_old',
> 'prefix' => '');
>
> //{app}/models/old_redacteur.php
>
> class OldRedacteur extends AppModel {
>
> var $name = 'OldRedacteur';
>
> var $useDbConfig = 'oldLocalDatabase';
>
> var $useTable = 'REDACTEURS';
>
> var $primaryKey = 'REDID';
>
> }
>
> //{app}/vendors/shells/recup_users.php
> class RecupUsersShell extends Shell {
> var $uses = array ('OldRedacteur', 'User');
> var $tasks = array('DbConfig');
>
> function main($rundry = false) {
> // this line outputs the right db config !
> $this->out('db config '.$this->OldRedacteur->useDbConfig);
>
> // this line doesn't work anymore
> $redacteurs = $this->OldRedacteur->find('all');
> ...
>
> The last line generates this error :
> the query (with the good fields from the table the model relates to) +
> <b>SQL Error:</b> 1146: Table 'popnews.REDACTEURS' doesn't exist</
> span>
> which indicates that the query is executed on the wrong database
> ("popnews" and not "popnews_old").
>
> I don't have the time to fill in a ticket for the moment, but does
> someone have this strange problem?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---