0
$sql = " UPDATE users
        SET  name = ?, role = ?, status = ?
        WHERE name = ?";
$stmt = execute_query($sql);
$stmt->execute(array($name, $role, $status, $name));
if($stmt->rowCount()) {
    echo "yes";
} else {
    echo "no";
    print_r($conn->errorInfo());

 

    function execute_query($sql)
    {
        global $conn;
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
        return $conn->prepare($sql);
    }

This throws the following, which means no row is affected. What mistake am I doing in the query?

(
[0] => 00000
[1] => 
[2] => 
)
aynber
  • 22,380
  • 8
  • 50
  • 63
Sam
  • 5,040
  • 12
  • 43
  • 95
  • 1
    Seems that you are updating a column with the same value .. $name , $name .. is this what you need .. (and could be that $name don't match in where) – ScaisEdge Nov 01 '16 at 17:34
  • No PHP expert but you seem to execute the query before binding the variables: `execute_query($sql)` – juergen d Nov 01 '16 at 17:34
  • Whatever it does, the function `execute_query($sql)` does not return a PDO object. How is this meant to work? Please take a look at a few explamples (you will find countless here on SO or on google or in the PDO documentation) and complare your code with the flow demonstrated there. – arkascha Nov 01 '16 at 17:35
  • 1
    Maybe it didn't find any rows to match? If you can, try turning on sql logging (`set global general_log = 'on'`), run the query, turn the log back off, then check the log for the `Execute` line to see if the query is what you think it is, and then check if there really were any matches. – aynber Nov 01 '16 at 17:45
  • aynber - this is correct. Please post this as answer – Sam Nov 01 '16 at 17:47
  • 1
    Once a question is closed, it can't be answered. – aynber Nov 01 '16 at 17:49
  • Ok. Thanks. juergen thanks. – Sam Nov 01 '16 at 17:57

0 Answers0