公共函数因内部查询报错,请求排查createRecord函数问题
createRecord Function Let’s walk through actionable steps to track down the hidden database error in your static function—right now, your error handling is missing key checks that are hiding what’s going wrong:
Add error checking for the
execute()call
You’re only verifying if the prepared statement was created successfully, but not whether the actual DELETE query ran without issues. Add this right after$delete_from_sessions->execute();:if (!$delete_from_sessions->execute()) { printf("DELETE execution failed: %s\n", $delete_from_sessions->error); }This will catch issues like invalid column names, missing table permissions, or malformed data that’s breaking the query.
Validate your database connection first
Before you even try to prepare a statement, make sure your$mysqlconnection is alive and valid. Toss this at the start of the function:if (!$mysql || $mysql->connect_error) { printf("Database connection failed: %s\n", $mysql->connect_error ?? "Unknown connection issue"); return false; // Handle this failure appropriately for your app }A dead connection will make the prepare call fail, but without this check, you might not realize that’s the root problem.
Debug the
loginclass methods
Your code cuts off at$seri...—if the error happens after the DELETE query, thecreateStringmethod (or subsequent serialized data steps) could be interacting with the database too, or have its own unhandled errors. Add error handling to those calls, and make sure you’re catching any exceptions or warnings from theloginclass.Double-check the data type for
uid
You’re binding$idas a string ('s'inbind_param). If theuidcolumn in yourcom_sessionstable is an integer, this could cause unexpected failures or silent data mismatches. Switch the type specifier to'i'ifuidis an int:$delete_from_sessions->bind_param('i', $id);Turn on strict MySQLi error reporting
For debugging, enable full error reporting at the top of your script to get detailed exceptions instead of silent failures:mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);This will force MySQLi to throw exceptions for any errors, which makes it impossible to miss where things are breaking.
Once you add these checks, run the function again—you’ll get specific error messages that point directly to the problem, whether it’s a connection issue, bad query syntax, permission problem, or data type mismatch.
内容的提问来源于stack exchange,提问作者ぽlっかいえゔぁん

