hi all,
i've been using a class for my database functions, example:
PHP Code:
Class Query {
var $action;
var $connect;
function Query($query,$sql) {
$this->action = mysql_query($query,$sql);
$this->connect = $sql;
}
function Error() {
if(mysql_errno($this->connect))
return 'Error #' . mysql_errno($this->connect) . ': ' . mysql_error($this->connect) . '<br />';
else
return false;
}
function FetchAssoc() {
return mysql_fetch_assoc($this->action);
}
function Free(){
if(is_resource($this->action) && get_resource_type($this->action) == 'mysql link'){
mysql_free_result($this->action);
}
}
function Close($sql){
mysql_close($sql);
}
}
there are also many more functions inside the class, but i have only listed a few. in my script, if i apply a query using this class for example:
PHP Code:
$selectQuery = 'SELECT * FROM `sample_table` WHERE `id` = 3 LIMIT 1';
$result = new Query($selectQuery,$sql);
if($result->Error()) echo $result->Error();
else {
// print our results
$row = $result->FetchAssoc();
echo "id is: " . $row['id'] . "<br />\n";
echo "name is: " . $row['name'] . "<br />\n";
$result->Free();
unset($row);
}
$result->Close($sql);
it all works fine. however i would like to write put that into a function such as called displayAllSamples(). the problem i have is that as soon as i do i get errors such as:
'mysql_query(): supplied argument is not a valid MySQL-Link resource in...'
for each time where it tries to use the functions from inside the class. i know the code for applying query is fine as it works if i don't use it in a function. how do i adapt my code/class/functions so it can be put into a new function?
thanks
|