The entered pdo statement inserts DEFAULT when the variable in BindParam is zero

I have this problem: I am using a prepared PDO report .... I want the BIND variable, but if the variable is NULL, it should Insert the DEFAULT VALUE field into MYSQL ...

I try IFNULL (: User_Login__Is_Active, DEFAULT), and I also tried: COALESCE (: User_Login__Is_Active, DEFAULT), Same error: PDOException: SQLSTATE [42000]: syntax error or access violation: 1064 You have an error in the SQL syntax;

How can you do this?

Check out this example:

        $stmt = $this->pdo->prepare('INSERT INTO user_login
                                        ( User_Login__ID,
                                          User_Login__Is_Active,
                                          User_Login__Created_Date )
                                   VALUES ( 
                                          :User_Login__ID,
                                          IFNULL(:User_Login__Is_Active, DEFAULT),
                                          :User_Login__Created_Date )');


    $stmt->bindParam(':User_Login__ID', $this->User_Login__ID, PDO::PARAM_INT);
    $stmt->bindParam(':User_Login__Is_Active', $this->User_Login__Is_Active, PDO::PARAM_STR, 100);
    $stmt->bindParam(':User_Login__Created_Date', $this->User_Login__Created_Date, PDO::PARAM_STR, 100);


    $this->User_Login__Is_Active = null;
+4
source share
1 answer

The keyword DEFAULTcannot be used inside the expression, it can replace only the entire expression.

DEFAULT() .

, DEFAULT DEFAULT(User_Login__Is_Active).

+6

All Articles