如何使用PDO在MySQL中存储BIGINT? [英] How do I store a BIGINT in MySQL using PDO?
问题描述
我们正在使用一个数据库,我们将Facebook id存储为BIGINT(20)。
创建表用户(
fb_id bigint(20)NOT NULL,
user_name varchar(30)NOT NULL,
CONSTRAINT uk_name unique(user_name),
CONSTRAINT pk_fb_id主键(fb_id)
)ENGINE = INNODB;
但是,PHP的PDO引擎只能插入PHP的最大整数值,即2147483647。 p>
$ stmt-> bindParam(':fb_id',$ this-> fb_id,PDO :: PARAM_INT);
我明白是非常明显的,因为我们受到PHP中整数的最大值的限制。我试图使用字符串 -
$ stmt-> bindParam(':fb_id',$ this-> fb_id, PDO :: PARAM_STR);
但仍然无效。
我想知道是否有一个解决方法将其存储为bigint。
我们正在使用一个数据库,我们将Facebook id存储为BIGINT(20)。
为什么你为什么这么做?
我认为普遍的共识是,Facebook ID不应该保存为数字类型,而应该保存为字符串。将它们保存为数字值不会产生任何优点 - 但有几个缺点。
I know this question has been asked more than once here, but I couldn't find a solution.
We are using a database where we are storing the facebook id as a BIGINT(20).
create table users(
fb_id bigint(20) NOT NULL,
user_name varchar(30) NOT NULL,
CONSTRAINT uk_name unique (user_name),
CONSTRAINT pk_fb_id primary key (fb_id)
)ENGINE=INNODB;
But the PDO engine of PHP can insert only the max integer value of PHP, i.e. 2147483647.
$stmt->bindParam(':fb_id', $this->fb_id, PDO::PARAM_INT);
This, I understand, is quite obvious since we are limited by the maximum value of integer in PHP. I tried to use the string -
$stmt->bindParam(':fb_id', $this->fb_id, PDO::PARAM_STR);
but still it doesn't work.
I want to know if there could be a workaround to store it as bigint.
We are using a database where we are storing the facebook id as a BIGINT(20).
Why oh why are you doing that?
I think general consensus is that Facebook ids should not be saved as numeric types, but as strings instead. Saving them as something numeric does not yield any advantages whatsoever – but several disadvantages.
这篇关于如何使用PDO在MySQL中存储BIGINT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!