(PHP 5 >= 5.3.0)

SQLite3Result::columnTypeباز گرداندن نوع ستون nام


public int SQLite3Result::columnType ( int $column_number )

باز گرداندن نوع ستون nام مشخص شده با column_number.



اندیس عددی مبنای صفر ستون.

Return Values

بازگرداندن اندیس نوع داده ستون مشخص شده با column_number (یکی از SQLITE3_INTEGER، SQLITE3_FLOAT، SQLITE3_TEXT، SQLITE3_BLOB، یا SQLITE3_NULL).

add a note add a note

User Contributed Notes 3 notes

phpnotes at carwash dot org
6 years ago
This function never returns any value other than 5, indicating SQLITE3_NULL.  SQLite 3 doesn't have column types, it has column affinities.  Different rows of the same table (and rows resulting from a SELECT) can hold values of different types.  Therefore this API cannot return anything useful, and the method appears to be using SQLITE3_NULL as a placeholder.

The function in useless and should be removed or marked as deprecated in future releases, so as not to give any programmer the false idea that the values returned are useful.
jean-marc at paratte dot ch
3 years ago
To find the type of columns, you need to 'query' the SQL sentence, 'fetchArray' the 1rst row, and then extract the name and type of each column.


function _sqlite_fetch_all( $db, $sql ) {

    $sqlite = new SQLite3( $db);

    if( $sqlite->lastErrorCode() ) return;

    $result = $sqlite->query( $sql );

    $result->fetchArray( SQLITE3_NUM );
    $fieldnames = [];
    $fieldtypes = [];
    for( $colnum=0; $colnum<$result->numColumns(); $colnum++) {
        $fieldnames[] = $result->columnName($colnum);
        $fieldtypes[] = $result->columnType($colnum);

    while( $row = $result->fetchArray( SQLITE3_NUM ) ) {

        for ($colnum=0; $colnum<count($row); $colnum++) {
            $col = &$row[$colnum];
            if (isset($fieldtype_encode_binary[$fieldtypes[$colnum]])) $col = $fieldtype_encode_binary[$fieldtypes[$colnum]]( $col );
        if ($resulttype == SQLITE3_ASSOC) $row = array_combine( $fieldnames, $row );
        $rows[] = $row;



    return $rows;

Remark 1: The type of a column is SQLITE3_NULL before any 'fetchArray' and 'false' after last fetched row.

Remark2 : The actual values of SQLITE3_INTEGER, SQLITE3_FLOAT, SQLITE3_TEXT, SQLITE3_BLOB, SQLITE3_NULL are 1, 2, 3, 4, 5.
hairbysubaru at gmail dot com
1 year ago
jean-marc is correct. SQLite determines column types dynamically based upon the returned record-set.
To Top