3 tier web dev with php

clareto

New Member
Messages
250
Reaction score
0
Points
0
I've been using asp.net and I've found VERY usefull the ms architecture for building web sites. I would like to do the same with php but I noticed that to achieve it, I would needed to write a *lot* of php. Using asp, i can inherit from the System.Data.DataSet object and I have table functionality, i.e. disconnected data. How can I handle data with php? do I need to create objects for each record and any kind of array/list/tree to manage a collection of them?

PEAR::DB, PEAR::MDB2... do I need them?
 

Xenon Design

New Member
Messages
160
Reaction score
0
Points
0
Well from what I can sort of understand of what ASP knowledge I have left, you want to make a database connection? Or do you want to store data in an array or something?
 

clareto

New Member
Messages
250
Reaction score
0
Points
0
tnx xenon...

when I retrieve data using mysql_query I get a recordset. To fetch the data, I put the data in objects using foreach and mysql_fetch_array.

Using asp I get the data and fill a DataSet object. In fact, an object which inherits from DataSet. With that object I can get records by columns and rows, its like a disconnected backup of the db table.

Using php I get the recordset and copy the data in a convenient object (with properties that match recordset columns). For each row in the recordset, I create an object and put it into an array. It works, but by doing i feel in the stone age... I just think there's a better way to manipulate disconnected data.

All that is keeping in mind the 3 tier model, so the bussiness layer is getting the data objects (DataSet or the arrays I dont like) from the data access layer.

tnx.
 

Xenon Design

New Member
Messages
160
Reaction score
0
Points
0
Well i can sort of see what you mean. I sort of miss some of ASP too...like being able to redirect even if the headers were written.

Anyway...why not use the mysql_result for retrieving data? That result will allow you to choose the row and field id. Heres an exapmple:

PHP:
mysql_pconnect('localhost', 'user', 'pass');
//I use pconnect to reduce strain on the server during high traffic
$sql = "SELECT * FROM database WHERE id > 50";
$query = mysql_query($sql);
$record_1 = mysql_result($query, 0, 0);
print $record_1;
Now if the db was set up so the id field was the first field, the above would then return the first record's id field. The field numbers and row result numbers are from 0 and up.

You got me so far? Its hard transferring from ASP to PHP...i felt your pain xD

The fetch array task is really for when your retrieving 1 row of data, the first row.

I hope this mini tut helps you in your transition :)
 

clareto

New Member
Messages
250
Reaction score
0
Points
0
thanks xenon, I didn't knew the mysql_result function... its very helpful!

It makes things easier, but I still dont know how to pass data between layers (or tiers). I mean, I dont want to send to the business layer a result from mysql_query. I would like to send any kind of array or data structure that dont have anything to do with the data access.
For example if I get 50 rows of student data, I dont want to send the result from mysql_query to the function that writes a log and to the template engine (like smarty). I want to send something like the asp's DataSet, which is completely database independent and disconnected.
In the case of 'student' I write a class (class Student) with name, code, age... and after that, I make an array of student objects (each one with the data of a row). The array is the thing that I send to the rest of the application. It works fine for me, but I feel it is not an elegant solution (and it is not so flexible and scalable!).

And I've been always in love with php. I just had a crush on asp.net, but I'm with php again. I just miss the 'pure oop feeling' of asp.

If there's any pear package or class library that would help me, please let me know, and if others handle this problem with other techniques pleasme let me know

Thanks
 

Xenon Design

New Member
Messages
160
Reaction score
0
Points
0
I dont really understand...from what I can gather...you want an easy way to write logs/rows of data into (example) a HTML table?

If you send abit of the asp.net ill have a look and see what I recognize and how it eould work in PHP :)
 
Top