note 101589 added to class.sqlite3result
| From: | alan71-at-free-fr at osu1 dot php dot net | Date: | Tue, 28 Dec 2010 14:34:00 +0000 |
| Subject: | note 101589 added to class.sqlite3result | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175274@lists.php.net to get a copy of this message | ||
Nevermind my previous note, it got mixed up with some other code and SQLite3Result does not
implement those interfaces.
But 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
----
Server IP: 195.221.21.36
Probable Submitter: 88.185.224.208
----
Manual Page -- http://www.php.net/manual/en/class.sqlite3result.php
Edit -- https://master.php.net/note/edit/101589
Del: integrated -- https://master.php.net/note/delete/101589/integrated
Del: useless -- https://master.php.net/note/delete/101589/useless
Del: bad code -- https://master.php.net/note/delete/101589/bad+code
Del: spam -- https://master.php.net/note/delete/101589/spam
Del: non-english -- https://master.php.net/note/delete/101589/non-english
Del: in docs -- https://master.php.net/note/delete/101589/in+docs
Del: other reasons-- https://master.php.net/note/delete/101589
Reject -- https://master.php.net/note/reject/101589
Search -- https://master.php.net/manage/user-notes.php