Re: Creating Arrays

From: Date: Thu, 12 Apr 2001 19:49:14 +0000
Subject: Re: Creating Arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-48358@lists.php.net to get a copy of this message
[posted and emailed] If you're looking for a simple way to work with databases I would use phplib. Phplib is a db abstraction layer which supports over a dozen databases including mysql. You can get the libraries at http://phplib.netuse.de/download/phplib-7.2c.tar.gz You will need to use "db_mysql.inc" I think using mysql specific functions is bad programming. Database specific calls should be abstracted out whenever possible. To do something like you would want to do you would use code like this: // create the db object $db = new DB_Sql; // initialize db parameters $this->Host = <your host>; $this->Database = <db>; $this->User = <user name>; $this->Password = <password>; // E.g. make a simple query $db->query("select username, uid, security_level from access where username='$f_username' and password='$f_password';"); $db->next_record(); $db_username = $db->f("username"); $si_userid = (int)($db->f("uid")); $si_security_level = (int)($db->f("security_level")); // putting the values in an array is trivial, but you should do it like this // or you will confuse your numeric ids with the ids that php puts in an array automatically $my_array["username"] = $db_username; $my_array["userid"] = $si_userid; On 11 Apr 2001 09:09:09 -0700, ashley@pcraft.com ("Ashley M. Kirchner") wrote: > > I need to convert an MySQL result into an Array...somehow. The >query returns the following: > > +----+-----------+ > | ID | Project | > +----+-----------+ > | 1 | Home | > | 2 | Work | > | 3 | Family | > | 4 | Misc. | > | . | ... | > | . | ... | > +----+-----------+ > > ...which I want to convert into: > >Array(1 => "Home", 2 => "Work", 3 => "Family", 4 => >Misc.", etc....); > > What's the best way to do this. > > AMK4 > >-- >W | > | I haven't lost my mind; it's backed up on tape somewhere. > |____________________________________________________________________ > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Ashley M. Kirchner <mailto:ashley@pcraft.com> . > 303.442.6410 x130 > SysAdmin / Websmith . 800.441.3873 x130 > Photo Craft Laboratories, Inc. . eFax 248.671.0909 > http://www.pcraft.com . 3550 Arapahoe > Ave #6 > .................. . . . . Boulder, CO 80303, USA -- Jeff Greer - B.S. computer science - Univ. MO - Rolla - I do web hosting and development. Details at http://www.singlesconnection.org/services/

« previous php.general (#48358) next »