You are here: class structure. « PHP « IT news, forums, messages
class structure.

Posted by Dustin Krysak on 01/20/05 04:30

Hi there, I am pretty new to writing classes (and pretty new to PHP
itself), but I was wondering what was the best format for constructing
classes. Now for example, i have written 2 versions of a class that
accomplish the exact same thing. And I was just wondering if there are
any advantages to either, or even if one was formatted more so to
standards. Just wanting to learn it the proper way from the get go. My
classes are formatted for use in flash remoting (hence the methodTable
stuff - you can ignore it). I guess my question refers more towards the
declaration of properties, etc.

[ VERSION 1 ]

<?php
class Sql {
// Set properties
//DB info
var $hostname_local = "localhost";
var $database_local = "mydb";
var $username_local = "root";
var $password_local = "password";
var $local;
var $query_rs_biz;
var $rs_biz;

function Sql() {
$this->methodTable = array(
"getRecords" => array(
"description" => "return a SQL record",
"access" => "remote",
"arguments" => array("")
)
);
}

//SQL
//Create method to retreive records
function getRecords() {

$this->local = mysql_pconnect($this->hostname_local,
$this->username_local, $this->password_local) or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($this->database_local, $this->local);
$this->query_rs_biz = "SELECT * FROM directory ORDER BY Business ASC";
$this->rs_biz = mysql_query($this->query_rs_biz, $this->local) or
die(mysql_error());

//return $this->row_rs_biz;
return $this->rs_biz;
}
}
?>


[ VERSION 2 ]

<?php
class Sql2 {
// Set properties
//DB info
var $hostname_local = "localhost";
var $database_local = "Blisting";
var $username_local = "root";
var $password_local = "URAredneck";

function Sql2() {
$this->methodTable = array(
"getRecords" => array(
"description" => "return a SQL record",
"access" => "remote",
"arguments" => array(),
"returns" => "sql records"
),
"getRecCount" => array(
"description" => "return the row count from the getRecords method",
"access" => "remote",
"arguments" => array(),
"returns" => "sql row count"
)
);
}

//SQL
//Create method to retreive records
function getRecords() {

$local = mysql_pconnect($this->hostname_local, $this->username_local,
$this->password_local) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($this->database_local, $local);
$query_rs_biz = "SELECT * FROM directory ORDER BY pID ASC";
$rs_biz = mysql_query($query_rs_biz, $local) or die(mysql_error());

//return results;
return $rs_biz;
}
}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация