enumerations // collections
| From: | Mitja Pagon | Date: | Mon, 10 Sep 2001 20:36:29 +0000 |
| Subject: | enumerations // collections | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-66812@lists.php.net to get a copy of this message | ||
I'm writting a class in PHP that has the following syntax
<?
require_once("consts.inc");
class User {
var $ID;
var $name;
var $lastname;
var $username;
var $password;
function GetUser($ID) {
$db = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASSWORD);
mysql_select_db(SQL_DATABASE, $db);
$RS = mysql_query("SELECT * FROM users WHERE ID=$ID", $db);
if ($fld = mysql_fetch_object($RS)) {
$this->ID = $fld->ID;
$this->name = $fld->name;
$this->lastname = $fld->lastname;
$this->username = $fld->username;
$this->password = $fld->password;
return true;
}
else {
return false;
} #end if
mysql_free_result($RS);
mysql_close($db);
}#end function
function AddUser() {
if ((empty($this->name)) or (empty($this->lastname)) or
(empty($this->username)) or (empty($this->password))) {
return false;
}
else {
$db = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASSWORD);
mysql_select_db(SQL_DATABASE, $db);
$SQL = "INSERT INTO users(name, lastname, username, password)
VALUES('$this->name', '$this->lastname', '$this->username',
'$this->password')";
mysql_query($SQL, $db);
return true;
} #end if
} #end function
} #end class
?>
What I want to do now is implement a method(function) named ListUsers that
will return all users from the database and asign the values to the objects
properties
The result should be look something like this(at lest thats how collections
look like in COM objects)
$user->item[i]->property
I hope I got my point accross.
Thanks in advance!
Mitja