如何使用PDO在MySQL中存储BIGINT? [英] How do I store a BIGINT in MySQL using PDO?

查看:165
本文介绍了如何使用PDO在MySQL中存储BIGINT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题不止一次地被问到,但是我找不到解决方案。



我们正在使用一个数据库,我们将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屋!

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