简体   繁体   English

如何从PHP插入NULL值?

[英]How to INSERT NULL value from PHP?

Let x is a column of the table t allowing NULL values. x为表t允许空值的列。

Which value should $value variable take for the following PDO statement to insert NULL value? $value变量应为以下PDO语句插入哪个值以插入NULL值?

$db->prepare("INSERT t SET x=:x")->execute(array(':x'=>$value));

You simply insert it as null : 您只需将其插入为null

$db->prepare("INSERT t SET x=:x")->execute(array(':x'=>null));

If you want, you can also add the data type of PDO::PARAM_NULL . 如果需要,还可以添加PDO :: PARAM_NULL的数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM