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
SQLite3Result クラス
(バージョン情報なし。おそらく SVN 版にしか存在しないでしょう)
導入
SQLite 3 拡張モジュールの結果セットを扱うクラスです。
クラス概要
SQLite3Result
{
/* メソッド */
}目次
- SQLite3Result::columnName — n 番目のカラムの名前を返す
- SQLite3Result::columnType — n 番目のカラムの型を返す
- SQLite3Result::fetchArray — 結果の行を、連想配列あるいは数値添字配列あるいはその両方で取得する
- SQLite3Result::finalize — 結果セットを閉じる
- SQLite3Result::numColumns — 結果セットのカラム数を返す
- SQLite3Result::reset — 結果セットを最初の行に戻す
alan71-at-free-fr
28-Dec-2010 06:34
claudiu at virtuamagic dot com
08-Mar-2010 02:34
fetchArray() will return bool(false) in case of 0 rows.
jonscully at gmail dot com
30-Nov-2009 01:35
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
