Hello, I am using a database class that I wrote for my project. I created a query variable that is accessible to the whole class, so that when you query the database, the class stores the query so you can use the other functions without telling it the query to use. My problem is that in a few of my functions, the query is showing up as a NULL value, but it does not in others.
here is a piece of my class:
protected $mysqlQuery;
## Query DB ##
public function query($query){
$this->mysqlQuery = mysql_query($query);
$rowNum = 0;
$fields = $this->getFieldNames();
while($row = $this->fetchArray()){
for($i = 0; $i < count($fields); $i++){
$results[$rowNum][$fields[$i]] = $row[$fields[$i]];
}
$rowNum++;
}
var_dump($this->mysqlQuery); // This returns the query properly
return $results;
}
## Fetch results of query ##
protected function fetchArray($query = ""){
var_dump($this->mysqlQuery); // This returns the query properly
if($query == ""){
return mysql_fetch_array($this->mysqlQuery);
}elseif($query != ""){
return mysql_fetch_array($query);
}else{
return false;
}
}
## Get number of rows in query ##
public function numRows($query = ""){
var_dump($this->mysqlQuery); // This returns the query as a NULL value
if($query == ""){
return mysql_num_rows($this->mysqlQuery);
}elseif($query != ""){
return mysql_num_rows($query);
}else{
return false;
}
}
I have tried changing the scope of the variable to public, and private and neither of those help to change the error. I have also had problems in the past with accidentally overriding variables to null values (like in an if()
statement to see if the value is equal to null, I set it to null with a = instead of ==), but I am reasonably sure that is not the problem here because I have looked specifically for that.
Thank you for any help that you can give,
Key Roche'