Skip to content

[Technical Debt]: Handle query() returning false in CI4 migration #3634

Closed

Description

@objecttothis

https://codeigniter.com/user_guide/installation/upgrade_412.html#baseconnection-query-return-values

As of CI 4.1.2 query() returns false when a query fails. We may need to go through the code and add a check on the return value. Formerly I believe it returned an empty object. This function is used extensively in the models, so we need to think this one through.

Activity

  1. added this to the 3.4.0 milestone on Jan 27, 2023
  2. added
    CodeIgniter4
    on Dec 12, 2023
  3. self-assigned this
    on Jun 20, 2024
  4. added a commit that references this issue on Jul 29, 2024
  5. added a commit that references this issue on Aug 3, 2024
  6. added 2 commits that reference this issue on Aug 26, 2024
  7. added 3 commits that reference this issue on Sep 6, 2024
  8. modified the milestones: 3.4.0, 3.5.0 on Nov 4, 2024
  9. changed the title [-]CI4: query() now returns false for failed queries[/-] [+][Technical Debt]: Handle query() returning false in CI4 migration[/+] on Apr 1, 2026
  10. jekkos commented on Oct 2, 2026

    @jekkos
    Member

    @CodeRabbit is this still an issue?

  11. coderabbitai commented on Oct 2, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    set -euo pipefail
    gh issue view 3634 --repo opensourcepos/opensourcepos --json title,body,state,comments,url,closedAt
    gh api repos/opensourcepos/opensourcepos --jq '{default_branch,updated_at}'

    Length of output: 1401


    🏁 Script executed:

    #!/bin/bash
    set -euo pipefail
    git branch --show-current
    git rev-parse HEAD
    fd -i '^(composer\.(json|lock)|Database\.php)$'
    rg -n -C2 --glob '*.php' -- '->query\(|DBDebug|database\.default\.DBDebug' . | head -260

    Length of output: 21622


    🤖 web_search executed:

    CodeIgniter 4 BaseConnection query returns false DBDebug exceptions 4.1.2 upgrade query return values current documentation

    Length of output: 1185


    🏁 Script executed:

    #!/bin/bash
    set -euo pipefail
    gh api repos/opensourcepos/opensourcepos/commits/master --jq '.sha'
    python - <<'PY'
    import json
    with open('composer.json') as f:
        data=json.load(f)
    print("CodeIgniter requirement:", data.get('require',{}).get('codeigniter4/framework'))
    with open('composer.lock') as f:
        data=json.load(f)
    for package in data.get('packages',[]):
        if package['name']=='codeigniter4/framework':
            print("CodeIgniter locked version:",package['version'])
    PY
    ast-grep outline app/Models/Tax.php --items all
    ast-grep outline app/Models/Sale.php --match 'get_all_suspended' --items all
    ast-grep outline app/Models/Reports/Inventory_low.php --items all
    ast-grep outline app/Config/Database.php --items all
    sed -n '80,140p' app/Models/Tax.php
    sed -n '1180,1210p' app/Models/Sale.php
    sed -n '1,95p' app/Models/Reports/Inventory_low.php
    sed -n '15,46p' app/Config/Database.php
    rg -n -C2 --glob '*.php' -- 'DBDebug\s*=|DBDebug.*=>|transException\s*\(' app

    Length of output: 10441


    @jekkos Yes. This remains an issue on current master (1b8ee2e3).

    The project uses CodeIgniter 4.7.4. A failed query() can still return false when DBDebug is disabled. The default database configuration disables DBDebug in production.

    Several methods still call getResultArray() without checking for false:

    The ?: [] fallback does not protect these calls. PHP calls getResultArray() first, which fails if $query is false.

    I recommend keeping #3634 open. Failed queries need explicit error handling before result access. For tax calculations, a database failure should not silently become an empty tax list.

    This conclusion comes from code inspection. I did not run database-failure tests.

    You are interacting with an AI system.

  12. added a commit that references this issue on Oct 8, 2026
    94aba61
  13. added a commit that references this issue on Oct 8, 2026
    9fef0bd
  14. added a commit that references this issue on Oct 19, 2026
    5060df0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CodeIgniter4enhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions