database class

From: Date: Mon, 01 Jan 2001 17:25:38 +0000
Subject: database class
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-32262@lists.php.net to get a copy of this message
Hi folks and happy new year to all of you. I just thought that I would need some class for easier communications with mysql. There should be some good (already complete) ones out there, but all that I have seen, haven`t been very good I must say or there have just been too little documentaion to use them well. So I thought I`ll try to make something my own. However, I haven`t actually dealed much with functions, classes, til now I`ve managed to get along pretty much without them. Today I thought it`s time... I have started with add_data and get_data functions, but probably they don`t work yet. However, I thought I will post them here and if anyone has suggestions how to make these things easier, more powerful, faster or whatever, maybe just how to make this thing work(!), then please get back to me. OK, here it is, pretty short one, but it`s just a beginning: Class DB { function get_data ($table,$fields) { $get_data = mysql_query("SELECT $fields FROM $table"); $get_pieces = strtok($fields,","); while($get_pieces) { $piece[] = $get_pieces; $get_pieces = strtok(","); } while($give_data = mysql_fetch_array($get_data)){ for($asi=0;$asi<=count($piece);$asi++){ $thing = $piece[$asi]; $field[$asi] = $give_data["$thing"]; } } return $field; } function add_data ($table,$fields,$data){ $add_data = mysql_query("INSERT INTO $table ($fields) VALUES ($data)"); } } And to use them: $see= new DB(); $see -> get_data('todaysnews','title,newsid'); echo $see; $see= new DB(); $see -> add_data('todaysnews','title,newsid','$value1,$value2'); However, this thing doesn`t actually seem to work. OK, Ill be waiting for your feedback before Ill go on. If I`m doing something completely wrong, I wouldn`t like to write the whole code like that. Thanks Siim Einfeldt itpunk@itpunk.com

« previous php.general (#32262) next »