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.

AlexDuchovny
View Replies:
nteaviation replied on at Permalink Reply
nteaviation
A custom block may be an easy way to accomplish that. You could make a new block called myIframe by copying the c5 core iframe block. Your dashboard form could provide the interface for the 3rd party datbase connection information. Your view.php could fetch the data and display it however you like.

Just an idea :)
AlexDuchovny replied on at Permalink Reply
AlexDuchovny
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
nteaviation replied on at Permalink Reply
nteaviation
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 :)
nteaviation replied on at Permalink Reply
nteaviation
Now that I think about it, the /concrete/blocks/content or html blocks may be a better starting place :)
AlexDuchovny replied on at Permalink Reply
AlexDuchovny
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.
nteaviation replied on at Permalink Reply
nteaviation
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.
AlexDuchovny replied on at Permalink Reply
AlexDuchovny
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!
ijessup replied on at Permalink Reply
ijessup
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);
nteaviation replied on at Permalink Reply
nteaviation
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
nteaviation replied on at Permalink Reply
nteaviation
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? :)
AlexDuchovny replied on at Permalink Reply
AlexDuchovny
c5 documentation has something similar:
http://www.concrete5.org/documentation/how-tos/understanding-and-bu...
but not that short and condensed.
ijessup replied on at Permalink Reply
ijessup
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
AlexDuchovny replied on at Permalink Reply
AlexDuchovny
Thx ijessup! Using ADODB is a great tip! Definitely gonna use it.
ijessup replied on at Permalink Reply
ijessup
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
AlexDuchovny replied on at Permalink Reply
AlexDuchovny
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 ;)
ijessup replied on at Permalink Reply
ijessup
Easy enough then! Connect to the alien database with ADOdb, execute a query, and dump the info into your page. :D

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!
Fernandos replied on at Permalink Reply
Fernandos
ijessup you genius! <8