PHP SQLite JSON Data Duplication

前端 未结 2 1860
伪装坚强ぢ
伪装坚强ぢ 2021-01-22 01:40

I have the following PHP code:

$testMessage = \"TESTMESSAGE\";

$db = new SQLite3(\'messages.sq3\');
$db->exec(\'CREATE TABLE messages(id INTEGER PRIMARY KEY,         


        
相关标签:
2条回答
  • 2021-01-22 01:56

    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.

    0 讨论(0)
  • 2021-01-22 02:13

    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

    0 讨论(0)
提交回复
热议问题