数据库为什么会变成这样?

WBOY
Release: 2016-06-23 13:23:52
Original
927 people have browsed it

我在使用PHP向数据库中插入数据时发现一个问题,当插入一个字段类型为varchar的值时,无论插入的内容是多少个0,数据库都默认认为是一个0。请教大神。why?这种情况该怎么处理。


回复讨论(解决方案)

上sql语句
表结果截图

INSERT INTO user (PhoneNumber,Password) VALUES (12312312312,000000)

INSERT INTO user (PhoneNumber,Password) VALUES ('12312312312','000000')

请加上单引号,谢谢

你把0 加上引号试试。

字符类型,sql语句里要给加上单引号

字符串需要用引号包围,否则会转为数字,00000转数字就是0,所以数据库中保存的就是0了。

varchar为字符类型
当你insert数据的时候,字符串变量需要加上引号。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!