Here's a snippet that might help you to write a fetchObject function that is also missing:
<?php
function fetchObject($sqlite3result, $objectType = NULL) {
$array = $sqlite3result->fetchArray();
if(is_null($objectType)) {
$object = new stdClass();
} else {
// does not call this class' constructor
$object = unserialize(sprintf('O:%d:"%s":0:{}', strlen($objectType), $objectType));
}
$reflector = new ReflectionObject($object);
for($i = 0; $i < $sqlite3result->numColumns(); $i++) {
$name = $sqlite3result->columnName($i);
$value = $array[$name];
try {
$attribute = $reflector->getProperty($name);
$attribute->setAccessible(TRUE);
$attribute->setValue($object, $value);
} catch (ReflectionException $e) {
$object->$name = $value;
}
}
return $object;
}
?>
Heavily inspired of Bergmann's Object Freezer :
https://github.com/sebastianbergmann/php-object-freezer/blob/master/Object/Freezer.php
The SQLite3Result class
Introduction
کلاس هندل نتیجه ضمیمه SQLite 3.
Class synopsis
SQLite3Result
{
/* Methods */
}Table of Contents
- SQLite3Result::columnName — باز گرداندن نام ستون nام
- SQLite3Result::columnType — باز گرداندن نوع ستون nام
- SQLite3Result::fetchArray — Fetches a result row as an associative or numerically indexed array or both
- SQLite3Result::finalize — بستن نتیجه
- SQLite3Result::numColumns — بازگرداندن تعداد ستونهای نتیجه
- SQLite3Result::reset — بازگرداندن نتایج به اولین ردیف
alan71-at-free-fr ¶
2 years ago
jonscully at gmail dot com ¶
3 years ago
Since SQLite3Result::numRows is unavailable, use:
<?php
if ($res->numColumns() && $res->columnType(0) != SQLITE3_NULL) {
// have rows
} else {
// zero rows
}
?>
Because when there are zero rows:
* SQLite3Result::fetchArray will return '1'
* SQLite3Result::numColumns will return '1'
* Column type for column '0' will be SQLITE3_NULL
