Velox Letum
01-10-2006, 01:20 AM
Okay, a while back I wrote a database abstraction class which allows me to use a universal set of functions while I could change however it handles it in the class. When a query was executed, it'd use the query's return reference as the key in an associative array for working easily with result sets.
This works fine with the MySQL extension, but after upgrading to PHP5 and attempting to use MySQLi (MySQL Improved extension), it returns an object. An object does not like to be used as the key in an array. Thus, I posted here for any advice you may have. Would it be possible to salvage this method? Or should I begin thinking about other ways to solve this problem?
Example function from my class:
public function sql_fetchrow($query_id = 0) {
if (!$query_id) {
// $query_id is the value of the return of a mysqli_query()
$query_id = $this->query_result;
}
if ($query_id) {
/* This was where I'd use the reference to fetch the row.
It retrieves the data correctly as I pass the query result outside the function.
However with MySQLi won't set $this->row[$query_id] as it returns an object now. */
$this->row[$query_id] = mysqli_fetch_assoc($query_id)
return $this->row[$query_id];
} else {
return FALSE;
}
}
This works fine with the MySQL extension, but after upgrading to PHP5 and attempting to use MySQLi (MySQL Improved extension), it returns an object. An object does not like to be used as the key in an array. Thus, I posted here for any advice you may have. Would it be possible to salvage this method? Or should I begin thinking about other ways to solve this problem?
Example function from my class:
public function sql_fetchrow($query_id = 0) {
if (!$query_id) {
// $query_id is the value of the return of a mysqli_query()
$query_id = $this->query_result;
}
if ($query_id) {
/* This was where I'd use the reference to fetch the row.
It retrieves the data correctly as I pass the query result outside the function.
However with MySQLi won't set $this->row[$query_id] as it returns an object now. */
$this->row[$query_id] = mysqli_fetch_assoc($query_id)
return $this->row[$query_id];
} else {
return FALSE;
}
}