Thread: help with oop
View Single Post
Old 10-06-2008, 01:47 AM   #1 (permalink)
sarmenhb
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default help with oop

what i'm trying to do with my class is instead of writeing

while($row = mysql_fetch_assoc($query)) {

echo $row['field'];

}

i'm trying to write my own function that will do this but i dont know or am kind of confuses to how i can output more fields(from sql) and if i did write a function how will i end the while loop with a paranthesis

here is my class

Code:
<?php

class dbconnect {

public $host;
public $username;
public $password;
public $database;
public $table;
public $query;


#===================================
#    Database Connection
#===================================
function connectdb($in_host,$in_username,$in_password,$in_database) {

$conn = mysql_connect($this->host = $in_host,$this->username = $in_username,$this->password=$in_password) or die(mysql_error());
mysql_select_db($this->database=$in_database)or die(mysql_error());

}

#=========================================
#    sql query
#=========================================

function query($in_query) {

$output = mysql_query($this->query=$in_query)or die(mysql_error());
return $output;



}


#=========================================
#    Alternate to mysql_fetch_assoc
#=========================================


function fetch($this->query($in_query),$field)) {

while($row = mysql_fetch_assoc($this->query($in_query)) {


echo $row['$field'];

}


}
if you have a similar class can i take a look at it?
__________________
no signature set
sarmenhb is offline  
Reply With Quote