/** * Internal method to fetch the next row in a result set * * @return Array Returns the field values */ public function fetch() { $current = sqlite_current($this->result, SQLITE_ASSOC); if (sqlite_valid($this->result)) { sqlite_next($this->result); } return $current ?: NULL; }
<pre> <?php $db = sqlite_open(dirname(__FILE__) . "/db.sqlite"); $res = sqlite_query("SELECT login FROM auth_tbl", $db); /* got rows? */ while (sqlite_has_more($res)) { /* fetch one row */ print_r(sqlite_current($res, SQLITE_ASSOC)); /* move along */ sqlite_next($res); } sqlite_close($db); ?> </pre>
public function next() { return sqlite_next($this->result); }
function sqlitem_next($result) { die('sqlitem_next'); return sqlite_next($result); }
function sqlitem_next($result) { return sqlite_next($result); }
sqlite_exec("DROP TABLE strings", $db); ///// $data = array(array(0 => 'one', 1 => 'two'), array(0 => 'three', 1 => 'four')); sqlite_query("CREATE TABLE strings(a VARCHAR, b VARCHAR)", $db); foreach ($data as $str) { sqlite_query("INSERT INTO strings VALUES('{$str[0]}','{$str[1]}')", $db); } echo "====BUFFERED====\n"; $r = sqlite_query("SELECT a, b from strings", $db); while (sqlite_valid($r)) { var_dump(sqlite_current($r, SQLITE_NUM)); var_dump(sqlite_column($r, 0)); var_dump(sqlite_column($r, 1)); var_dump(sqlite_column($r, 'a')); var_dump(sqlite_column($r, 'b')); sqlite_next($r); } /// XXX this doesn't match PHP5, but ours looks more correct?? /* echo "====UNBUFFERED====\n"; $r = sqlite_unbuffered_query("SELECT a, b from strings", $db); while (sqlite_valid($r)) { var_dump(sqlite_current($r, SQLITE_NUM)); var_dump(sqlite_column($r, 0)); var_dump(sqlite_column($r, 'b')); var_dump(sqlite_column($r, 1)); var_dump(sqlite_column($r, 'a')); sqlite_next($r); } */ /////
function valid() { return sqlite_next($this->result); }
echo "num rows: " . sqlite_num_rows($rh) . "\n"; // simple fetch_array loop echo "fetching results\n"; while ($result = sqlite_fetch_array($rh)) { var_dump($result); } // simple fetch_object loop // php5 dumps objects differently /* echo "fetching results object\n"; sqlite_rewind($rh); while ($result = sqlite_fetch_object($rh)) { var_dump($result); }*/ // rewind/next loop sqlite_rewind($rh); while (sqlite_next($rh)) { $result = sqlite_current($rh); var_dump($result); $b = sqlite_has_more($rh); echo "has_more?\n"; $b = sqlite_valid($rh); echo "valid?\n"; var_dump($b); // if (function_exists('sqlite_key')) // echo "on row: ".sqlite_key($rh)."\n"; } // seek sqlite_seek($rh, 3); $result = sqlite_current($rh); var_dump($result); // seek