Preparing a MySQL INSERT/UPDATE statement with DEFAULT values

后端 未结 4 1690
谎友^
谎友^ 2020-12-06 10:38

Quoting MySQL INSERT manual - same goes for UPDATE:

Use the keyword DEFAULT to set a column explicitly to its default value. This makes it easier to w

4条回答
  •  执念已碎
    2020-12-06 10:55

    Try changing this:

    $statement = $pdoObject->
        prepare("INSERT INTO table1 (column1,column2) values (?,?)");
    $statement->execute(array('value1','DEFAULT'));
    

    To this:

    $statement = $pdoObject->
        prepare("INSERT INTO table1 (column1,column2) values (?,DEFAULT)");
    $statement->execute(array('value1'));
    

    It seems to me that your original code will give you this:

    INSERT INTO table1 (column1,column2) values ('value1','DEFAULT')
    

    My code should give you this:

    INSERT INTO table1 (column1,column2) values ('value1',DEFAULT)
    

提交回复
热议问题