我有下表:
CREATE TABLE `Plot` (
`idPlot` int(11) NOT NULL,
`ListPrice` decimal(9,2) DEFAULT NULL,
`WebPrice` decimal(9,2) DEFAULT NULL,
`BottomPrice` decimal(9,2) DEFAULT NULL,
PRIMARY KEY (`idPlot`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
如果要传递一个空字符串,我想在十进制字段中存储一个NULL值。我似乎只能存储0.00。
我正在使用Meekrodb进行更新:
$db->update('Plot', array(
'ListPrice' => $one['ListPrice'],
'BottomPrice' => $one['BottomPrice'],
'WebPrice' => $one['WebPrice']
), "idPlot=%s", $one['idPlot']);
我的输入数组如下所示:
Array
(
[idPlot] => 6
[ListPrice] => 99,999.00
[BottomPrice] =>
[WebPrice] =>
)
Meekro运行:
UPDATE `Plot` SET `ListPrice`='99999.00', `BottomPrice`='', `WebPrice`='' WHERE idPlot='6'
我得到:
Array
(
[0] => Array
(
[idPlot] => 6
[ListPrice] => 99999.00
[WebPrice] => 0.00
[BottomPrice] => 0.00
)
)
存储在数据库中。
有什么办法使它用NULL而不是0.00填充字段?
谢谢
请注意空字符串之间的区别:
$foo = '';
...和一个NULL
值:
$foo = NULL;
所述的print_r()函数不显示差异; 您需要使用var_dump()来准确地转储变量:
$data = array('', NULL);
print_r($data);
var_dump($data);
Array
(
[0] =>
[1] =>
)
array(2) {
[0]=>
string(0) ""
[1]=>
NULL
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句