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 names of the tables are correct, the data that I pass inside the method too, database is fine, but it fails and returns no error. When I try to return statement data into 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 error list, it is empty. Do I need to set something to make it update?Anyone has an idea what can it be? Database is created like this:
<?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 ;
?>
$statement->bind_param('si', $username, $userid);
instead of$statement->bind_param('is', $userid, $username);
– Hassaan