添加值“001"到mysql数据库 [英] Add value "001" to mysql database

查看:169
本文介绍了添加值“001"到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将值006"添加到 MySql 行,但它显示为6"!对我的代码有任何修复吗?

I am trying to add the value "006" to an MySql row, but it shows up as "6"! any fixes on my code ?

$id = "006";

mysql_query("INSERT INTO Table (id) VALUES ($id) ");

谢谢,

推荐答案

如果 id 是数字列如整数,006 相同6 所以没有办法显式保存 006 因为它和 6 完全一样.

If id is a numeric column such as an integer, 006 is the same as 6 so there isn't a way to explicitly save 006 since its exactly the same as 6.

但是,如果您想将该整数检索为 3 位零填充字符串,您可以使用 LPAD 函数将其填充为 0左侧:

But if you want to retrieve that integer as a 3-digit, zero-padded string, you could use the LPAD function to pad it with 0's on the left side:

SELECT LPAD(id, 3, '0') as id FROM table;

这篇关于添加值“001"到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆