phpeveryday.com

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


PHP N-tier: Data Access Tier Using PHP ADOdb

Tag: n-tier, multitier, adodb, data access tier,    Category: PHP Application
post: 12 Mar 2008 read: 199


PHP N-Tier Strategy Step By Step Tutorial - Part 4: In this post, we will build data access tier. We use PHP Adodb. About PHP Adodb, you can read at here.

For this practice, create a folder named "ntier" within www/test. Place your all PHP ADOdb folder at here. Thus, you have www/test/ntier/adodb.

Then create a file named "dataaccess.php" within www/test/ntier. Enter following code


<?
include('adodb/adodb.inc.php'); 

$databasetype = 'mysql';
$server = 'localhost';
$user   = 'root';
$password = 'admin';
$database = 'test';

$db = ADONewConnection($databasetype); 
$db->debug = false; 
$db->Connect($server, $user, $password, $database); 

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

if (!$recordSet) 
  print $conn->ErrorMsg(); 
else 
  while (!$recordSet->EOF) { 
    print $recordSet->fields[0].' '.$recordSet->fields[1].' '.$recordSet->fields[2].'<BR>'; 
  $recordSet->MoveNext();       
}    

$recordSet->Close(); # optional 
		
$db->Close();

?>

Test it. Open your browser. point to http://localhost/test/ntier/dataacces.php.

Next post, we will talk about business logic layer. Don't miss it.




| 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
mod_rewrite - Part 1: create your "fantasy" URL

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


615
posting