Msqli php query update doesn't work, returns no errors
I wrote the following code:
public static function updateUser($userid, $username){
$query = 'UPDATE users SET username=? WHERE id=?';
$statement = $GLOBALS["DB"]->prepare($query);
$statement->bind_param('is', $userid, $username);
$statement->execute();
$statement->store_result();
if ($statement->affected_rows == 1){
return 1;
}
else{
return $statement;
}}
The table names are correct, the data I pass inside the method is fine too, but it fails and returns no error. When I try to return these instructions to the console, it gives me this:
mysqli_stmt Object ([affected_rows] => 0 [insert_id] => 0 [num_rows] => 0 [param_count] => 2 [field_count] => 0 [errno] => 0 [error] => [error_list] => Array () [sqlstate] => 00000 [id] => 3) {"Status": "Success"}
I checked the error list, it is empty. Do I need to install something to keep it updated? Does anyone have an idea what this might be? The database is created as follows:
<?php
require_once ("simplecms-config.php");
require_once ("./Functions/database.php");
// Create database connection
$databaseConnection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($databaseConnection->connect_error)
{
die("Database selection failed: " . $databaseConnection->connect_error);
}
// Create tables if needed.
prep_DB_content();
$GLOBALS['DB'] = $databaseConnection ;
?>
+3
source to share
2 answers