Extend mysqli_result - whether it uses store_result () or use_result ()

I wrote a mysqli child with a query method that returns a mysqli_result child. This result will have additional methods unique to my application.

public MySQL extends mysqli
{
    public function query($query)
    {
        if ($this->real_query($query)) {
            if ($this->field_count > 0) {
                return new MySQL_Result($this);
            }
            return true;
        }
        return false;
    }

}

class MySQL_Result extends mysqli_result
{
    public function fetch_objects() {
        $rows = array();
        while($row = $this->fetch_object())
            $rows[$row->id] = $row;
        return $rows;
    }
}

I can’t understand if fetch_object()buffered or unbuffered SQL data is used.

The constructor mysqli_resultdoes not appear in mysqli.php, so I do not see its call $mysqli->store_result()or $mysqli->use_result().

I tried adding these methods to MySQL, but none of the functions echo.

    public function store_result($option='a') {
        echo "STORE RESULT<br/>";
    }

    public function use_result($option='a') {
        echo "USE RESULT<br/>";
    }

Does this mean that the constructor mysqli_resultdoesn’t call either? If so, how does it access SQL data when called fetch_object?

................

SQL. , , , , , $mysqli->store_result().

PHP/OOP . .

+4
2

mysqli_result MySQL ( )

. , MySQL PHP PHP. , () . . , . , , . " " , .

-

  • . MySQL
  • mysqli_query mysqli_get_result ( ) mysqli_result

0

, mysqli_result SQL.

, . , SQL- .

/* Open a connection */
$mysqli = new MysqlDB("127.0.0.1", "phpuser", "phpuserpw", "wishlist");
if (mysqli_connect_errno())
   return;

if ($result = $mysqli->query("SELECT * FROM wishers")) {

    $res2 = $mysqli->query("SELECT * FROM wishes");

    echo "Mem = ".memory_get_usage()."<br/>";

    while($row = $result->fetch_row()) {
        $row2 = $res2->fetch_row();

        printf ("1: ID=%s,  Name=%s, Pass=%s<br/>",$row[0],$row[1], $row[2]);
        printf ("2: ID=%s,  WisherID=%s<br/>", $row2[0], $row2[1]);

        echo "Row Mem = ".memory_get_usage()."<br/>";
    }

1: ID = 1, Name = Tom, Pass = tomcat

2: ID = 3, WisherID = 2

1: ID = 2, Name = Jerry, Pass = jerrymouse

2: ID = 4, WisherID = 2

1: ID = 6, Name = Tommy, Pass = tomcat

2: ID = 5, WisherID = 1

..........................

, .

0

Source: https://habr.com/ru/post/1664855/


All Articles