How do I store a BIGINT in MySQL using PDO?

泄露秘密 提交于 2020-01-11 02:27:06

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11938384/how-do-i-store-a-bigint-in-mysql-using-pdo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!