Monthly Archives: March 2017

Adapter Pattern OO Design PHP Example

Quoting from Url http://www.oodesign.com/adapter-pattern.html
“The adapter pattern is adapting between classes and objects.
Like any adapter in the real world it is used to be an interface, a bridge between two objects.
In real world we have adapters for power supplies, adapters for camera memory cards, and so on. Probably everyone have seen some adapters for memory cards. If you can not plug in the camera memory in your laptop you can use and adapter.
You plug the camera memory in the adapter and the adapter in to laptop slot. That’s it, it’s really simple.”

It is more clear to understand with example.
PHP Examples

  1. Example 1
    class clsSong {
    	private $title;
    	private $genre
    	function __construct($title, $genre) {
    		$this->title = $title;
    		$this->genre = $genre;		
    	}
    	
    	function getTitle() {
    		return $this->title;
    	}
    	
    	function getGenre() {
    		return $this->genre;
    	}
    }
    
    class clsSong_Adapter {
    	private $objSong;
    	function __construct(clsSong $objSong) {
    		$this->objSong = $objSong;			
    	}
    	
    	function getTitleGenre() {
    		return $this->objSong->getTitle()."/".$this->objSong->getGenre();
    	}
    }
    
    //implementation 
    $objSong = new clsSong("Nothing Else Matter", "Heavy Metal");
    echo $objSong->getTitle()."/".$objSong->getGenre();
    echo "<br>";
    
    $objSngAdapt = new clsSong_Adapter($objSong);
    echo $objSngAdapt->getTitleGenre();
    
    

    Continue reading

DB2 Export Data To CSV With PHP Interface

Reporting with large number of records could be cumbersome if you view it on web page and download the data to CSV or Excel format.
Especially if you are dealing with hundred thousand or millions records.

DB2 has feature for export data or download records directly to external storage i.e your local hard disk.
The way is to specify the data to be exported by supplying an SQL SELECT statement and then use db2 export to download directly to CSV format.

The DB2 syntaxt for this download is db2 export to <filepath/filename> of del <SQL Select statement>.
More complete explanation please go to IBM url https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0008303.html

This blog post will explain how to use DB2 export with PHP.
The PHP page calls DB2 export which transfer records to CSV format and after file created and finish transfering then the CSV is zipped.
Continue reading