A
A
Anastasia2021-06-28 06:48:21
PHP
Anastasia, 2021-06-28 06:48:21

How to get more than one record in SQLite?

Hello. To be honest, I don't quite understand why it behaves differently than the conditional mysql pdo. Why when I do:

$db = new SQLite3('mysqlitedb.db');
p($db->query('SELECT * FROM test')->fetchArray(SQLITE3_ASSOC));

always returns only one record?

In the vastness of the network, I found such a crutch (I can’t call it otherwise)
function resultSetToArray($queryResultSet){
    $multiArray = array();
    $count = 0;
    while($row = $queryResultSet->fetchArray(SQLITE3_ASSOC)){
        foreach($row as $i=>$value) {
            $multiArray[$count][$i] = $value;
        }
        $count++;
    }
    return $multiArray;
}

It already issues all records
Prompt:
1. why at normal request - one record?
2. For what reason can I see the entire array only through this crutch?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-06-28
@nastya97core

1. Because that's how the function works. RTFM

SQLite3Result::fetchArray - Fetches a single row from the result set and places it in an associative array, numbered array, or both.

2. This is not a crutch, but a regular use of the function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question