Reputation: 538
I have a Mysql table with a decimal column that allows NULL
s. If I pass 0 as double in a PHP's prepared statement, my 0 turns NULL in the Mysql column.
How can I get the value 0 instead of NULL
?
PS: I use the following code to insert the value
$query2 = "insert into TableName
(Id, anotherId, date,
`MinValue`, `MaxValue`,
`oneMoreId`, `Comment`)
values
(?, ?, '2016-06-23',
?, ?,
?, ?)";
$stmt = $connection->prepare($query2);
$stmt->bind_param('iiddis', $Id, $anotherId,
$minValue, $maxValue, $oneMoreId,
$comment);
$stmt->execute();
EDIT: after answer by @YourCommonSense, I figured there was an error in my code. Above the lines that I posted, I had a change of value from 0 to NULL
. My fault, sorry, guys!
Upvotes: 0
Views: 754
Reputation: 157930
If I pass 0 as double in a PHP's prepared statement, my 0 turns NULL in the Mysql column.
This is not true.
If you pass 0, then it gets stored as 0.
But if you pass NULL, then it gets stored as NULL.
Therefore, you are passing NULL value, not 0.
Check your values and cast them if necessary.
Upvotes: 3