class structure.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
}
}
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux