Cakephp kann die Datenbank nicht im laufenden Betrieb ändern

Ich versuche, aus mehreren Datenbanken eine Verbindung über eine Schleife herzustellen, aber CakePHP kann dies nicht änderndatabase, nur andere infos (wie user / pass / host).

app / Config / database.php

<?php
class DATABASE_CONFIG {
    [...]

    public $default = array(
        [..] // Where I have the companies
    );
    public $client = array(
        [...] // Fakke settings, because I will change it on-the-fly
    );
}

app / Controller / CronController.php

$companies = $this->Company->find('all');
foreach($companies as $company) {
    $settings = array(
        'datasource' => 'Database/Mysql',
        'host' => $company['Company']['host'],
        'login' => $company['Company']['username'],
        'password' => $company['Company']['password'],
        'database' => $company['Company']['database'],
    );

    ConnectionManager::drop('client');
    $db = ConnectionManager::create('client', $settings);

    try {
        debug($this->MyModel->find('first'));
    } catch (Exception $e) {
        echo '<pre>';
        echo "Exception: ",  $e->getMessage(), "\n";

        /*
        debug($this->MyModel->getDataSource());

        Outputs:

        [...]
        [config] => Array
            (
                [persistent] => 
                [host] => 0.0.0.0 // CORRECT HOST
                [login] => root // CORRECT LOGIN
                [password] => pass // CORRECT PASSWORD
                [database] => database1
                [port] => 3306
                [datasource] => Database/Mysql
                [prefix] => 
                [encoding] => utf8
            )
        [...]
        */
    }
}

Es gibt die erste Verbindung zurück und für alle anderen kann ich bei MyModel nichts auswählen, weil es falsch ist. Es scheint, dass die Verbindung von Benutzer / Kennwort / Host in Ordnung ist, aber die Datenbank wird nicht geändert. Da der Benutzer keine Berechtigung zur Auswahl in der CD-Datenbank hat, wird der Fehler angezeigt.

Array
(
    // First connection, connection ok, MyModel return nothing
)

// Second connection
Exception: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'database_user_2'@'localhost' for table 'my_model'

// Third connection
Exception: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'database_user_3'@'localhost' for table 'my_model'

// Fourth connection
Exception: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'database_user_4'@'localhost' for table 'my_model'

// Fifth connection
Exception: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'database_user_5'@'localhost' for table 'my_model'

Vielen Dank!

Antworten auf die Frage(2)

Ihre Antwort auf die Frage