Skip to content

Mysqli last query error #18728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

domenico-pinto-www
Copy link

This pull request introduces a new property last_query_error in the mysqli class.
The property stores the SQL query that caused the most recent error, providing developers with easier debugging and error tracking.

How to test:

  • Create a simple PHP script to connect to the database and intentionally execute an invalid query (e.g., SELECT * FROM non_existing_table).
  • Catch the exception and retrieve the $mysqli->last_query_error property.
  • Verify that it contains the failed SQL query.

@devnexen
Copy link
Member

devnexen commented Jun 1, 2025

Not judging the code correctness (CI failure is very legit) but the relevance of it. Not sure what to think but things to consider perhaps like Should we always store this info (ie hiding it behind a ini setting, disabled by default) ? If you do not get feedback in a timely manner, I suggest trying to defend your case in the internal mailing list. Cheers.

@kamil-tekiela
Copy link
Member

Are you aware that this already exists? https://www.php.net/manual/en/mysqli.error.php

Besides, what exactly is the point in that? If you can catch the exception then you already have all this info in the exception.

@kamil-tekiela
Copy link
Member

When creating a PR do not add the .patch file. You should also provide sufficient unit testing for the new feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants