Hello, good afternoon.
I started migrating a MySQLi class of procedural to Object Oriented and two functions of this class left me in doubt.
During the migration of the fetchRow and fetch_array functions I was struck by a strong doubt, since in the procedural class it is pretty weird and I did not find a way to do it similar to the object-oriented version.
function &fetchRow($sql, $type = 'DBARRAY_ASSOC') {
$this->sql = & $sql;
$queryresult = $this->execute_query(true, $this->connection_master);
$returnarray = $this->fetch_array($queryresult, $type);
$this->free_result($queryresult);
return $returnarray;
}
function fetch_array($queryresult, $type = 'DBARRAY_ASSOC') {
$result = @$this->functions['fetch_array']($queryresult, $this->fetchtypes["$type"]);
return $result;
}
I'll also leave here the code for the execute_query function that appears in the code:
function &execute_query($buffered = true, &$link) {
$this->connection_recent = & $link;
if ($queryresult = $this->functions[$buffered ? 'query' : 'query_unbuffered']($link, $this->sql)) {
// unset $sql to lower memory .. this isn't an error, so it's not needed
$this->sql = '';
return $queryresult;
} else {
// unset $sql to lower memory .. error will have already been thrown
$this->sql = '';
}
}
And here are my OOP codes that are not working correctly ...
public function fetchRow($query, $type = MYSQLI_ASSOC) {
$this->Process = self::query($query);
return $this->Process->fetch_array($type);
}
public function fetch_array($query, $type = MYSQLI_ASSOC) {
$this->Process = $this->_Engine->query($query);
return $this->Process->fetch_array($type);
}
The codes were the same because I had no idea how it was done in the procedural version.
Thank you in advance!