index/src/Data/MariaDB/MariaDBResultNative.php

47 lines
1 KiB
PHP
Raw Normal View History

2022-09-13 15:13:11 +02:00
<?php
// MariaDBResultNative.php
// Created: 2021-05-02
// Updated: 2024-08-03
2022-09-13 15:13:11 +02:00
namespace Index\Data\MariaDB;
use mysqli_result;
use mysqli_stmt;
use RuntimeException;
2022-09-13 15:13:11 +02:00
/**
* 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);
2022-09-13 15:13:11 +02:00
$result = $_result;
}
parent::__construct($result);
}
public function next(): bool {
if(!($this->result instanceof mysqli_result))
return false;
2022-09-13 15:13:11 +02:00
$result = $this->result->fetch_array(MYSQLI_BOTH);
if($result === null)
return false;
2022-09-13 15:13:11 +02:00
$this->currentRow = $result;
return true;
}
public function close(): void {
try {
$this->result->close();
} catch(\Error $ex) {}
2022-09-13 15:13:11 +02:00
}
}