PDO bindParam into one statement?

前端 未结 5 1805
刺人心
刺人心 2020-12-02 19:14

Is there a way I can put these bindParam statements into one statement?

$q = $dbc -> prepare(\"INSERT INTO accounts (username, email, password) VALUES (:u         


        
5条回答
  •  甜味超标
    2020-12-02 20:06

    Example 2 on the execute page is what you want:

    $sth->execute(array(':calories' => $calories, ':colour' => $colour));
    

    You may want to look at the other examples too. With question mark parameters, it would be:

    $q = $dbc -> prepare("INSERT INTO accounts (username, email, password) VALUES (?, ?, ?)");
    $q->execute(array($_POST['username'], $_POST['email'], $_POST['password']));
    

    If those are the only columns, you can just write:

    $q = $dbc -> prepare("INSERT INTO accounts VALUES (?, ?, ?)");
    $q->execute(array($_POST['username'], $_POST['email'], $_POST['password']));
    

提交回复
热议问题