phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP N-tier: Building Business Logic

Tag: n-tier, multi-tier, application architecture, application design, business logic, nusoap   Category: PHP Application
post: 15 Mar 2008 read: 171


PHP N-Tier Strategy Step By Step Tutorial - Part 5: After create connection to database at this post, we will process this data. We prepare this data in order to can to send using webservices. We named this: business logic layer.

This practice only work well for php 4. In php 5, we will talk next serial post. Because there is embedded function in php 5. First, copy library of nusoap within www/test/ntier/lib. If you don't understant to place nusoap, please read this post.

Open again file dataacces.php within www/test/ntier. Update like following:


<?
// call library
require_once ( './lib/nusoap.php' ); //nusoap
require_once ('adodb/adodb.inc.php');//adodb

// create instance
$server = new soap_server();

// initialize WSDL support
$server->configureWSDL( 'hello' , 'urn:hellowsdl' );

// place schema at namespace with prefix tns
$server->wsdl->schemaTargetNamespace = 'urn:hellowsdl';

// register method
$server->register('books',  // method name
array(), // input parameter
array('return'=>'xsd:array'),
'urn:hellowsdl' , // namespace
'urn:hellowsdl#hello', // soapaction
'rpc', // style
'encoded', // use
'Load list of book to the caller' // documentation
); 

// configuration database
define(__databasetype__,'mysql');
define(__server__,'localhost');
define(__user__,'root');
define(__password__,'admin');
define(__database__,'test');


// method
function books(){
  $db = ADONewConnection(__databasetype__); 
  $db->debug = false; 
  $db->Connect(__server__, __user__, __password__, __database__); 

  $recordSet = &$db->Execute('select * from books'); 

  if (!$recordSet){
	return new soap_fault('Server','',$conn->ErrorMsg()); 
  } else { 
    while (!$recordSet->EOF) { 
	  $books[] = array('id'=>$recordSet->fields[0],
	                   'title'=>$recordSet->fields[1],
					   'author'=>$recordSet->fields[2]
	                  );
      $recordSet->MoveNext();       
    }    

    $recordSet->Close();	#optional	
    $db->Close();
  }
  
  // return value to client
  $obj = new soapval('return','array',$books);
  return $obj->serialize();  
  
}


$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

Then, test it. Open your browser. Point to http://localhost/test/ntier/dataacces.php. You will get like this:

business logic use wsdl




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
CAPTCHA - part 3 : "Are you human or ....?" (Build Your CAPTCHA)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting