The SQLite3Result class

(PHP 5 >= 5.3.0, PHP 7)

Введение

Класс предоставляющий доступ к результирующему набору расширения SQLite 3.

Обзор классов

SQLite3Result {
/* Методы */
public string columnName ( int $column_number )
public int columnType ( int $column_number )
public array fetchArray ([ int $mode = SQLITE3_BOTH ] )
public bool finalize ( void )
public int numColumns ( void )
public bool reset ( void )
}

Содержание

Коментарии

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
2009-11-30 03:35:09
http://php5.kiev.ua/manual/ru/class.sqlite3result.html
fetchArray() will return bool(false) in case of 0 rows.
2010-03-08 04:34:20
http://php5.kiev.ua/manual/ru/class.sqlite3result.html
Автор:
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
2010-12-28 08:34:00
http://php5.kiev.ua/manual/ru/class.sqlite3result.html
According to sqlite3result.columntype, and also per my experience, columnType() doesn't return anything other than SQLITE3_NULL. Consequently, the test suggested in the comment that tries to identify whether a column is NULL is incorrect.

The right thing to do appears to be to test if ($result->fetchArray())[0] == null.
2014-05-23 08:30:20
http://php5.kiev.ua/manual/ru/class.sqlite3result.html
I use the following code to get num_rows:

<?php
...
$nrows 0;
$result->reset();
while (
$result->fetchArray())
   
$nrows++;
$result->reset();
return 
$nrows;
...
?>
2014-10-10 18:43:29
http://php5.kiev.ua/manual/ru/class.sqlite3result.html
in response to jan at bootfinder dot co dot uk (comment #115891) about getting num_rows...

how about (not tested)... ?

<?php // do cleans before and after if needed

for ( $nrows 0isarray($result->fetchArray()); ++$nrows );
return 
$nrows;

?>
2021-03-02 04:56:11
http://php5.kiev.ua/manual/ru/class.sqlite3result.html

    Поддержать сайт на родительском проекте КГБ