user1831020
user1831020

Reputation: 215

PDO Problems with 0 and NULL

I have a customer table that I cannot change. It has a varchar field, that contains either NULL or 5.

I am trying to change that to a 1/0 (tinyint 1) in my field.

if ($row['varfield'] == '7') {
    $row['varfield'] = 1;
} else {
    $row['varfield'] = 0;
}

$stmt = $db->prepare("INSERT INTO table(col1) VALUES(?)");
$stmt->execute(array($row['varfield']));

However I am getting the error in my SQL saying that the col1 cannot be nullable...

Upvotes: 1

Views: 203

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67948

However I am getting the error in my SQL saying that the col1 cannot be nullable...

So set the column to be nullable in the database.

Upvotes: 1

Related Questions