Search code examples
phppdobindvalue

How to bindValue in array?


I have a many things to insert into database colums.

    $connect->prepare("INSERT INTO users (username, password, message, date, time, id) VALUES (:username, :password, :message, :date, :time, :id");

Instead of binding them all, I created a array:

    $IDs = array($username, $password, $message, $time, $date, $ID);

How do I take each variable from this array and bind it? I am completely lost with PDO.


Solution

  • use:

    $sth->execute(array(':username' => $username, ':password' => $password, $message, $time, $date, $ID))
    

    and for others...