+ Reply to Thread
Results 1 to 7 of 7

Thread: 3 tier web dev with php

  1. #1
    clareto is offline x10 Sophmore clareto is an unknown quantity at this point
    Join Date
    Oct 2005
    Posts
    125

    3 tier web dev with php

    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?

  2. #2
    Xenon Design's Avatar
    Xenon Design is offline x10Hosting Member Xenon Design is an unknown quantity at this point
    Join Date
    May 2006
    Location
    Behind your couch!
    Posts
    80

    Re: 3 tier web dev with php

    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?

    Website under construction -- Ask me anything about Web 2.0

  3. #3
    clareto is offline x10 Sophmore clareto is an unknown quantity at this point
    Join Date
    Oct 2005
    Posts
    125

    Re: 3 tier web dev with php

    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.

  4. #4
    Xenon Design's Avatar
    Xenon Design is offline x10Hosting Member Xenon Design is an unknown quantity at this point
    Join Date
    May 2006
    Location
    Behind your couch!
    Posts
    80

    Re: 3 tier web dev with php

    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 Code:
    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($query00);
    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

    Website under construction -- Ask me anything about Web 2.0

  5. #5
    clareto is offline x10 Sophmore clareto is an unknown quantity at this point
    Join Date
    Oct 2005
    Posts
    125

    Re: 3 tier web dev with php

    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

  6. #6
    Xenon Design's Avatar
    Xenon Design is offline x10Hosting Member Xenon Design is an unknown quantity at this point
    Join Date
    May 2006
    Location
    Behind your couch!
    Posts
    80

    Re: 3 tier web dev with php

    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

    Website under construction -- Ask me anything about Web 2.0

  7. #7
    oab's Avatar
    oab
    oab is offline
    x10 Lieutenant oab is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Olympia, WA
    Posts
    459

    Re: 3 tier web dev with php

    this one helped me get started hopefully it will do the same to you. its very easy to understand.

    http://www.freewebmasterhelp.com/tutorials/phpmysql/1
    there are some better ways to set up the loop though.


    oh yea i forgot to ask, you are using mysql right?
    Last edited by oab; 01-13-2007 at 11:25 AM.
    http://www.teamoab.com

    aim:dknigh73
    msn:d_knight_3@hotmail.com

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  4. [PHP] PHP For Starters
    By Complex in forum Tutorials
    Replies: 24
    Last Post: 06-14-2008, 11:40 PM
  5. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers