Help with Mysqli procedural to object-oriented class migration

Asked

Viewed 86 times

2

Hello, good afternoon.

I started to migrate a Mysqli class from procedural to Object Oriented and two functions of that class left me in doubt.

During the migration of functions fetchRow and fetch_array I had a strong doubt, since in the procedural class she is very strange and I did not find a way to make her similar in 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 leave the function code here too execute_query 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 properly...

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 stayed the same because I had no idea how it was done in the procedural version.

Thank you in advance!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.