Skip to content

SQLite3Result::fetchArray Doesn't Handle Join Statement Properly #20300

@loay-ali

Description

@loay-ali

When i tried using ( join ) statement for fetching data , sqlite3 tend to overwrite the column name if it appears in the other table

  • eg:

table-a

ID Name Foreign_id
1 bar 2

table-b

ID Name
2 foo

When i try to join them

SELECT * FROM table-a a JOIN table-b b ON(a.foreign_id=b.id)

i get the result as follows

[
  array(
  'ID' => 2,
  'name' => 'foo',
  'foreign_id' => 2
  )
]

i suggest prefixing the columns names with the table aliases name to clarify and avoid overwriting

So the result would be like this

[
 array(
  'a.ID' => 1,
  'a.name' => 'bar',
  'a.Foreign_id' => 2,
  'b.ID' => 2,
  'b.name' => 'foo'
 )
]

thanks in advance

From manual page: https://php.net/sqlite3result.fetcharray

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions