PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
PrObLeM
Forum Contributor
Posts: 418 Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:
Post
by PrObLeM » Tue Mar 09, 2004 12:30 am
I know i should test this but does anyone think this method for a database class will work?
Code: Select all
<?php
function select($what, $db, $where, $where_val)
{
$return_array = array();
$this->connect();
$result = mysql_query("SELECT $what FROM $db WHERE $where='$where_val'");
$row = mysql_fetch_object($result);
$exp_what = explode(", ", $what);
foreach($exp_what as $var)
{
$adding = array_push($return_array, $var=> $row->$var);
}
return $return_array
}
?>
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Mar 10, 2004 2:11 pm
Pretty limeted functionality, I'd say. But it likes look it would work. I'd suggest to change this line:
Code: Select all
$result = mysql_query("SELECT $what FROM $db WHERE $where='$where_val'");
to something like:
Code: Select all
$result = mysql_query("SELECT $what FROM $db WHERE $where='$where_val'",$this->connection);
This way you can use your class to connect to different databases and db hosts in one script.