downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

SQLite3Result::columnName> <SQLite3Stmt::reset
[edit] Last updated: Fri, 17 May 2013

view this page in

La classe SQLite3Result

(No version information available, might only be in SVN)

Introduction

Une classe qui représente les résultats d'une base de données SQLite 3.

Synopsis de la classe

SQLite3Result {
/* Méthodes */
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 )
}

Sommaire



SQLite3Result::columnName> <SQLite3Stmt::reset
[edit] Last updated: Fri, 17 May 2013
 
add a note add a note User Contributed Notes SQLite3Result - [3 notes]
up
1
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
up
0
alan71-at-free-fr
2 years ago
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
up
0
claudiu at virtuamagic dot com
3 years ago
fetchArray() will return bool(false) in case of 0 rows.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites