index/src/Data/MariaDB/MariaDBResultNative.php

46 lines
1 KiB
PHP

<?php
// MariaDBResultNative.php
// Created: 2021-05-02
// Updated: 2024-08-03
namespace Index\Data\MariaDB;
use mysqli_result;
use mysqli_stmt;
use RuntimeException;
/**
* Implementation of MariaDBResult for mysqlnd.
*
* @internal
*/
class MariaDBResultNative extends MariaDBResult {
public function __construct(mysqli_stmt|mysqli_result $result) {
if($result instanceof mysqli_stmt) {
$_result = $result->get_result();
if($_result === false)
throw new RuntimeException($result->error, $result->errno);
$result = $_result;
}
parent::__construct($result);
}
public function next(): bool {
if(!($this->result instanceof mysqli_result))
return false;
$result = $this->result->fetch_array(MYSQLI_BOTH);
if($result === null)
return false;
$this->currentRow = $result;
return true;
}
public function close(): void {
try {
$this->result->close();
} catch(\Error $ex) {}
}
}