PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] How to get current DB connection name in Cakephp 2.x

 January 20, 2022     cakephp     No comments   

Issue

I have two(default and test) db connections in my database.php:

public function __construct() {
        $this->default = array(
            'datasource' => 'Database/Mysql',
            'driver' => 'mysql',
                'persistent' => false,
                'encoding' => 'utf8',
                'prefix' => 'shaufel_',
                'host' => 'localhost',
                'database' => 'db',
                'login' => 'root', /*** replace this ***/
                'password' => 'root', /*** replace this ***/
        );

        //test db
        $this->test = $this->default;
        $this->test['database'] = $this->test['database'].'_test';
    }

How can I get the current DB connection NAME in my Model ? That means for example : if(current_db is testDB) do something. I use Cakephp 2.9.7.


Solution

I found it by myself: $this->getDataSource()->config['database']



Answered By - handkock
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing