.Net Framework, Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML

Ado.netAsp.Net 2.0SQLC-SharpXMLFrameworkIISXMLWebServiceArchitecture
UMLProject ManagementSDLCMethodologiesDesign PatterenOOPWCF.Net RemotingWWF
MVPMVCSilver LightN-HibernateAjaxJ-QuerySEO-MarketingSite MapPhp

Deal with Custom object in php

Object oriented php development.

Here we learn how to deal with custom object and collection object in php, How we can keep the business logic separetly from design code, as we do in asp.net devlopment.
We have expert php mysql developer in mumbai india, We can provide Php JQuery, php with mysql, php with ajax, php webservice, SEO compitable php design and more. Please contact us to know more about our service.
In php development we can keep the business logic and data interaction code separately from html design code. In example i will explain a authentication process with code.

HTML form design
Form submit & deal with custom object
<?php
1:include "Classes/UserDetails.php";
2:include "Secure/DataConnection.php";
3:include "DTOObjects/UserDetailsDTO.php";
4:
5:if($_POST['frmaction']=="submitted")
6:{
7: $dtoObj=new UserDetailsDTO();
8:
9: $obj = $dtoObj->GetUser($_POST['username'], $_POST['userpass']);
10:
11: if($obj!=null)
12: {
13: echo $obj->get_Username();
14: $_SESSION['username']=$_POST['username'];
15: header("Location:phpstore\default.php");
16: }
17: else
18: {
19: echo "<font color='red'>Authentication failed. Invalid username / password.</font>";
20: }
21:
22:}
23:
24:?>
25:
26:<form action="index.php" method="post">
27:<input type="hidden" name="frmaction" value="submitted">
28:<table>
29:<tr><td>User Id :</td><td><input name="username" type="text"></td></tr>
30:<tr><td>Password :</td><td><input name="userpass" type="password"></td></tr>
31:<tr><td></td><td><input type="submit" value="Enter"></td></tr>
32:</table>
33:</form>
34:
User class design
User class being used as an object in php
the reference given on top Classes/UserDetails.php
1:
2:<?php
3:
4:class UserDetails {
5:
6: // explicitly adding class properties are optional - but is good practice
7: var $UserId;
8: var $Username;
9: var $Userpass;
10: var $IsActive;
11:
12: public function get_UserId() {
13:
14: return $this->UserId;
15:
16: }
17:
18: public function set_UserId($UserId) {
19:
20: $this->UserId =$UserId;
21:
22: }
23:
24:public function get_Username() {
25:
26: return $this->Username;
27:
28: }
29:
30: public function set_Username($Username) {
31:
32: $this->Username =$Username;
33:
34: }
35:
36: public function get_Userpass() {
37:
38: return $this->Userpass;
39:
40: }
41:
42: public function set_Userpass($Userpass) {
43:
44: $this->Userpass =$Userpass;
45:
46: }
47:
48:}
49:
50:
51:?>
52:
UserDTO Class design & inteaction with database ?
DTO object design in php
<?php
1:
2:
3:
4:class UserDetailsDTO
5:{
6:
7:
8: // This is an example of returning a single entity.
9: public function GetUser($username,$userpass)
10: {
11:
12: $obj=null;
13:
14: // get teh result set.
15: $query="SELECT * FROM UserDetails where username= '". $username ."' and userpass='". $userpass ."'";
16: // echo $query ."<br>";
17: $result = mysql_query($query);
18:
19: // loop through result set
20: if($row = mysql_fetch_array($result))
21: {
22:
23: $obj=new UserDetails();
24:
25: $obj->set_Username($row['username']);
26: $obj->set_Userpass($row['userpass']);
27:
28:
29: }
30:
31: //mysql_close($con);
32:
33: return $obj;
34: }
35:
36:
37:
38:
39:}
40:
41:
42:?>
43:
Leave your comment.
Name
Email
Comments
Tell Us8880+5 =

Reduce your Dialy IT Cost, Consult with us
Stay healthy in recession

Advertisement
Sponsored by

Privacy Policy ©2009 ETG Consultancy, All Rights Reserved Terms & Conditions
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML