Second MySQL DB Connection with Doctrine
Permalink 2 users found helpful
OK, it's been a while since I use Concrete5. And everything seems different now especially witn Doctrine for database connection and ORM.
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
Snippet of my database.php
Honestly, I am lost as to how I can accomplish this -- the second mysql connection with doctrine.
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',
Viewing 15 lines of 21 lines. View entire code block.
Honestly, I am lost as to how I can accomplish this -- the second mysql connection with doctrine.
"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
There you go!