How to show some data from a third party database?
Permalink 4 users found helpful
I'm relatively new to concrete5 so my question may sound a little bit stupid. I have an area on the page where i have to show some extra data from a third party database (basically an image and a few lines of text). Right now the only solution, i came up with, is inserting an iframe with some php-script behind it. But it there any "concrete-way" to do it?
Thank you in advance for your help.
Thank you in advance for your help.
Sounds like a concrete-way to do it. A few questions to that:
1. I haven't seen a c5 core iframe block (no such block in concrete/blocks)
2. How to provide a database interface from the dashboard?
Thank you for your help
1. I haven't seen a c5 core iframe block (no such block in concrete/blocks)
2. How to provide a database interface from the dashboard?
Thank you for your help
Opps, sorry. iframe is a free add-on package. just install, copy and mangle that the stuff in the /block directory. Not knowing how you connect to the 3rd party database make is difficult to visualize, although all that could be just hardcoded in your view.php. I would not worry about adding database connection information to the dashboard UI for now. get it working and then add functinallity of you really need it :)
There may be a better block to "canibalize" other than iframe or even a more "MVC" compliant approach :)
There may be a better block to "canibalize" other than iframe or even a more "MVC" compliant approach :)
Now that I think about it, the /concrete/blocks/content or html blocks may be a better starting place :)
I see. So it's a html-content block where view.php fetches data from the database and generates some html from it, right?
Basically an iframe-solution implemented as an concrete-block.
Basically an iframe-solution implemented as an concrete-block.
Yes. Once you get your custom block to fetch and display your database data (which you said you are already doing via some backend php scripts) then you can decide if you want to extend the desktop UI for you custom block to support some database connection parameters. Do you know how to create a new custom block from an existing block? There are serveral things that you need to modify to make if work and not conflict with the c5 core blocks.
I've read a couple of tutorials and c5 wiki-article on blocks and played with creating some simple blocks. But i don't mind hearing some tips at all!
You can access other databases (even database engines that aren't MySQL) with the built in ADOdb class.
// Load another database for some reason $db = Loader::db( 'newserver', 'newuser', 'newpassword', 'newdatabase', true); $db->Execute('select * from TestTable2'); // return to the original db session $db = Loader::db(null, null, null, null, true);
Oh, using ADOdb is a good idea :)
Here is how I "create my own custom content block":
1.) Copy the directory /concrete/blocks/content to /blocks/my_content
2.) Edit the db.xml -
change the line:
<table name="btContentLocal">
to
<table name="btMyContentLocal">
3.) edit the controller.php -
change the line:
class ContentBlockController extends BlockController {
to
class MyContentBlockController extends BlockController {
change:
protected $btTable = 'btContentLocal';
to
protected $btTable = 'btMyContentLocal';
4.) Install your new block via the Dashboard/Add Functionality
Here is how I "create my own custom content block":
1.) Copy the directory /concrete/blocks/content to /blocks/my_content
2.) Edit the db.xml -
change the line:
<table name="btContentLocal">
to
<table name="btMyContentLocal">
3.) edit the controller.php -
change the line:
class ContentBlockController extends BlockController {
to
class MyContentBlockController extends BlockController {
change:
protected $btTable = 'btContentLocal';
to
protected $btTable = 'btMyContentLocal';
4.) Install your new block via the Dashboard/Add Functionality
The above instructions should work for just about any block. Do you think I should submit this as a "how to" or has someone already done it? :)
c5 documentation has something similar:
http://www.concrete5.org/documentation/how-tos/understanding-and-bu...
but not that short and condensed.
http://www.concrete5.org/documentation/how-tos/understanding-and-bu...
but not that short and condensed.
This may be a little advanced, but check out my (unfinished) objects and attributes development package. Specifically the models folder.
Scroll down to my last post:
http://www.concrete5.org/community/forums/customizing_c5/new-object...
Check out the new_object.php and new_object_list.php files. Those should get you from alien database to c5 kosher fairly quickly! :D
- IJ
Scroll down to my last post:
http://www.concrete5.org/community/forums/customizing_c5/new-object...
Check out the new_object.php and new_object_list.php files. Those should get you from alien database to c5 kosher fairly quickly! :D
- IJ
Thx ijessup! Using ADODB is a great tip! Definitely gonna use it.
No prob! I marked this as a helpful thread. c5 can be stupid powerful when you use it as more than just a CMS and more like a Database Management System.
Using ADOdb is great for querying a database, but turning the items in the query in to objects make for some serious geeky fun! :p
Using ADOdb is great for querying a database, but turning the items in the query in to objects make for some serious geeky fun! :p
I believe it's too high for me right now :) The good thing is - in my case i just need to output some plain html ;)
Easy enough then! Connect to the alien database with ADOdb, execute a query, and dump the info into your page. :D
Something like this:
That should get you started!
Something like this:
// Load another database for some reason $db = Loader::db( 'newserver', 'newuser', 'newpassword', 'newdatabase', true); // Query other database $r = $db->query("SELECT * FROM table WHERE column1 = ? order by column2 asc", array('value for column1')); $items = array(); while ($row = $r->fetchRow()) { $items[] = $row['column3']); } // Do something with results foreach($items as $i) { echo $i; } // return to the original db session $db = Loader::db(null, null, null, null, true);
That should get you started!
ijessup you genius! <8
Just an idea :)