2

我有下表:

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] => 
)

米克罗运行:

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 填充字段???

谢谢

4

2 回答 2

1

请注意空字符串之间的区别:

$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
}
于 2013-10-10T14:12:22.290 回答
1

我相信你必须在不带引号的情况下将值插入为 NULL

于 2013-10-10T14:14:52.353 回答