Note that there are some explanatory texts on larger screens.

plurals
  1. POCache-issue changing Cakephp database settings on the fly
    primarykey
    data
    text
    <p>I'm building a Website in Cakephp with variable databases. I did this with the following code:</p> <p>CONTROLLER: </p> <pre><code>$db_host = $DB_SET['Project']['db_host']; //From other database $db_user = $DB_SET['Project']['db_user']; $db_pass = $DB_SET['Project']['db_pass']; $db_database = $DB_SET['Project']['db_database']; ConnectionManager::create("client_db", array( 'datasource' =&gt; 'Database/Mysql', 'driver' =&gt; 'mysql', 'persistent' =&gt; false, 'host' =&gt; $db_host, 'login' =&gt; $db_user, 'password' =&gt; $db_pass, 'database' =&gt; $db_database, 'prefix' =&gt; '', 'encoding' =&gt; 'UTF8', 'port' =&gt; '', )); $DB_LINE = $this-&gt;Page-&gt;findPage('3'); </code></pre> <p>MODEL: </p> <pre><code>class Page extends Model { public $useDbConfig = 'client_db'; function findPage($pagenr) { $page = $this-&gt;find('first', array( 'conditions' =&gt; array ( 'Page.id' =&gt; $pagenr) )); return $page; } } </code></pre> <p>Now I also need to change of tables in the database on the Fly. I do this using(Controller):</p> <pre><code>$tbl_current = array('tbl_cheques', 'tbl_wishes'); $this-&gt;Modelname-&gt;useTable = $tbl_current[$pageid]; //Getting the pageID from an url parameter. </code></pre> <p>Everything works fine, only if I don't wait a while before clicking another page I get this error: </p> <pre><code>Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Page.fqlkdf' in 'field list' </code></pre> <p>This because Cake still have the previous table in his Cache. If I wait a minute and then I change the page it works fine. Any suggestions for this problem? Thanks in advance,</p> <p>Aäron</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload