为什么它使用 php 在我的数据库中插入 0 而不是空格?
我有一个插入:
$sql = 'INSERT into orders SET
fax_int_prefix = "'.$_SESSION['fax_int_prefix'].'",
fax_prefix = "'.$_SESSION['fax_prefix'].'",
fax_first = "'.$_SESSION['fax_first'].'",
fax_last = "'.$_SESSION['fax_last'];
所有这些字段的值是它们在插入之前是空白的。下面是我在插入之前回显的其中一个示例:
$_SESSION[fax_prefix] =
出于某种原因,它插入整数 0,而不是应有的空白值或 null。为什么它在我的数据库中插入 0 而不是空格?
I have an insert:
$sql = 'INSERT into orders SET
fax_int_prefix = "'.$_SESSION['fax_int_prefix'].'",
fax_prefix = "'.$_SESSION['fax_prefix'].'",
fax_first = "'.$_SESSION['fax_first'].'",
fax_last = "'.$_SESSION['fax_last'];
The value of all of these fields is that they are blank right before the insert. Here is an example of one of them I echo'd out just before the insert:
$_SESSION[fax_prefix] =
For some reason it inserts the integer 0, instead of a blank value or null, as it should. Why is it inserting 0's instead of blank spaces into my DB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查表的结构。它可能不是
char
或varchar
类型(或者它是并且默认值设置为“0”)。为此,您可以使用 phpmyadmin、SQLyog 或其他 MySql 管理程序。编辑:如果您想存储整数,但可以选择无值,请确保该类型可为空。即:
column_name INT(n) DEFAULT NULL
Check the structure of your table. It's possible that it is not of type
char
orvarchar
(or that it is and has a default value set to '0'). To do this you can use phpmyadmin, SQLyog or other MySql admin programs.Edit: If you want to store integers, but have the option of no value then make sure the type is nullable. i.e.:
column_name INT(n) DEFAULT NULL
检查数据库的架构。它们很可能是整数字段等。
或者
可能有帮助。另外,仅仅打印出变量并不是好的检查,而是使用 var_dump()。
Check the schema of your database. Most likely they are integer fields or such.
or
might help. Additionally just printing out a variable is no good check, rather use var_dump().