Sam*_*ele 4 insert sqlbindparameter default-value dbo
我有这个问题:我正在使用PDO预处理语句....我想BIND变量但是如果变量为NULL则必须在MYSQL中插入字段的DEFAULT VALUE ...
我正在尝试使用IFNULL(:User_Login__Is_Active,DEFAULT),我也尝试过:COALESCE(:User_Login__Is_Active,DEFAULT),相同错误:PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL中有错误句法;
你怎么能这样做?
看这个例子:
$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;
Run Code Online (Sandbox Code Playgroud)