Repository navigation
DB: the query log is opt-in; a connection failure throws instead of printing - #13
Merged
Merged
Conversation
Query log: Database::setQueryLogEnabled(true) turns it on (off by default, for every instance). When off nothing is stored, getAllQueries() returns an empty array and getLastQuery() returns null. When on it keeps the most recent Database::QUERY_LOG_LIMIT (5000) statements. getQueryCounter() and getOriginCounters() are unaffected, and a logger set with setLogger() still receives every statement. Connection: MySQL::connect() throws a DbException with the fixed message DbException::CONNECTION_FAILED instead of printing the error and exiting; isConnectionError() tells it apart from a failed statement. The driver's message and code are kept on the previous exception. A charset the server rejects is a connection failure too. The charset is set with mysqli::set_charset(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DqZUi2UiBJP6rZoCSRcdpE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
The query log is opt-in
Database::setQueryLogEnabled(true)turns the query log on; it is off by default and the switch applies to everyDatabaseinstance.Database::isQueryLogEnabled()reads it.getAllQueries()returns an empty array andgetLastQuery()returnsnull(it also returnsnullfor an empty log, where it used to raise an undefined-offset notice).Database::QUERY_LOG_LIMIT= 5000 statements (the previous limit let it reach 5001).getQueryCounter()andgetOriginCounters()work whether the log is on or off. The origin lookup no longer collects call arguments.setLogger()still receives every statement; that sink is chosen by the application and is not gated by the switch.A connection failure throws instead of printing
MySQL::connect()throws aDbExceptionwith the fixed messageDbException::CONNECTION_FAILED("Database connection failed."). It no longer prints anything and no longer callsexit.DbException::isConnectionError()tells a connection failure apart from a failed statement.getPrevious()carries its message and code, andgetErrorCode()returns the driver's error number. The previous exception is created by the framework, so its stack trace does not hold the arguments of the connect call.mysqli::set_charset()instead of aSET namesstatement, soreal_escape_string()uses it too. A charset the server rejects is now a connection failure (it used to be ignored). An emptydatabase.mysql.charsetsets nothing.connect()tries again.Compatibility
getAllQueries()/getLastQuery()(for debug output, or a query-count assertion in a test) get an empty array /nulluntil they callDatabase::setQueryLogEnabled(true). Add that call where the application decides it is in debug mode, before the queries it wants to see.DbExceptionat the first query, which goes to their own exception handling like any otherDbException. Code that catchesDbExceptionaround a query and treats every failure as a statement error can checkisConnectionError().database.mysql.charsetnow fails the connection instead of leaving the server default in place.Tests
DbQueryLogTest(switch, cap, counters, logger),MySQLConnectFailureTest(fixed message, no output, cause kept, retry, charset through the driver, rejected charset) and three cases inDbExceptionTest. They run without the mysqli extension: the connect step is split intoopenConnection()andapplyCharset(), which the tests script.🤖 Generated with Claude Code
https://claude.ai/code/session_01DqZUi2UiBJP6rZoCSRcdpE