Re: enumerations // collections
| From: | Richard Lynch | Date: | Wed, 12 Sep 2001 05:15:10 +0000 |
| Subject: | Re: enumerations // collections | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66996@lists.php.net to get a copy of this message | ||
First of all, you're going to have an awfully slow site if you end up
calling mysql_connect as often as it looks like you will.
You really only want to call mysql_connect once per script...
Collections in PHP are handled with arrays.
http://php.net/array
--
WARNING richard@zend.com address is an endangered species -- Use
ceo@l-i-e.com
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
----- Original Message -----
From: Mitja Pagon <mitja@hatchbit.com>
Newsgroups: php.general
To: <php-general@lists.php.net>
Sent: Monday, September 10, 2001 3:36 PM
Subject: enumerations // collections
> 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
>
>
>
>
>
>