Skip to content

fix: return own query error from MySQLi error() - #10845

Open
paulbalandan wants to merge 1 commit into
codeigniter4:developfrom
paulbalandan:mysqli-error-own-connection
Open

paulbalandan wants to merge 1 commit into
codeigniter4:developfrom
paulbalandan:mysqli-error-own-connection

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
Fixes #10839

This changes two things:

  • error() now returns the link's own errno and error whenever the connection is open. It reads the connect error only when connID is false.
  • connect() stores the connect error of that connection in a private $connectError, so the not-connected case no longer depends on PHP's process-wide value. It is reset at the start of each connect() call and set on all three failure paths: a thrown exception, a false return from real_connect(), and a failed set_charset().

The stored message is the same sanitized text as the DatabaseException thrown by connect(). Before, error() returned the raw driver message.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: MySQLi Connection::error() returns another connection's connect error after a failed connect anywhere in the process

2 participants