Second MySQL DB Connection with Doctrine2 users found helpful
Here's what I plan to do. I have another database that contains information that I need to display on my Concrete5 site. It has no Concrete5 tables. Just my own tables.
My plan is to create a class and store it in application/src/MyData/MyData.php. I need to know how to connect to my second database connection from here. I do have my second MySQL connection details in the array in application/config/database.php. I am not to sure about how to use the DatabaseManager and/or Doctrine to connect to it. I did find the other thread about connecting a second DB, but that is for MongoDB. I am lost... haven't used Doctrine before.
Continuing from that, if I get MyData.php to connect to my second MySQL, my next plan is create a block that will instantiate MyData class and get the data. In the block controller, I would probably have
The plan to be used in my block controller
$mydata = new MyData(); $display_data = $mydata->get($limit, $page);
Snippet of my database.php
return array( 'default-connection' => 'concrete', 'connections' => array( 'concrete' => array( 'driver' => 'c5_pdo_mysql', 'server' => 'localhost', 'database' => 'plainc5', 'username' => 'root', 'password' => '', 'charset' => 'utf8' ), 'second_db_conn' => array( 'driver' => 'c5_pdo_mysql', 'server' => 'localhost', 'database' => 'my_data_db',
Honestly, I am lost as to how I can accomplish this -- the second mysql connection with doctrine.
$this->conn = \Database::connection('connection_name');
"connection_name" comes from my database.php, where I set my second database settings. Now I can use it anywhere within the class by referring to $this->conn, for example
$stmt = $this->conn->query("select * from widget");
There you go!