Skip to content Skip to sidebar Skip to footer

Php Sqlite Json Data Duplication

I have the following PHP code: $testMessage = 'TESTMESSAGE'; $db = new SQLite3('messages.sq3'); $db->exec('CREATE TABLE messages(id INTEGER PRIMARY KEY, message CHAR(255));');

Solution 1:

The default is to have the data with both numeric and string keys, merged in the same array.

You need to use $results->fetchArray(SQLITE3_NUM) or $results->fetchArray(SQLITE3_ASSOC) to get numeric and string keys respectively. The default is SQLITE3_BOTH, which I've always hated.

Solution 2:

Both $row[1] and $row['message'] will give you the same data. This is because on technique uses the numerical index of the column and the other uses the name. They are both included in the column so that you can use either way to access them. It does not indicate any sort of duplication in the database itself.

Here you can see the documentation and how to tell PHP which version you want. By default it gives you both: http://php.net/manual/en/sqlite3result.fetcharray.php

Post a Comment for "Php Sqlite Json Data Duplication"