Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store a BIGINT in MySQL using PDO?

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.

like image 330
banskt Avatar asked Aug 13 '12 16:08

banskt


People also ask

Can I use PDO with MySQL?

PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases. So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries.

How do you write PDO?

$pdo = new PDO($dsn, $user, $passwd); A new PDO object is created. We pass the constructor the data source name and the user name and password. The PDO class represents a connection between PHP and a database server.

Is PDO safer than MySQLi?

There is no difference in security. The main difference between PDO and Mysqli is that PDO supports various databases and mysqli supports only MySQL. MySQLi is also a bit faster. PDO supports 12 different drivers, opposed to MySQLi, which supports MySQL only.

What is PDO SQL?

PDO (PHP Data Objects) is an abstraction layer for your database queries and is an awesome alternative to MySQLi, as it supports 12 different database drivers. This is an immense benefit for people and companies that need it. However, keep in mind that MySQL is by far the most popular database.


1 Answers

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.

like image 80
CBroe Avatar answered Sep 20 '22 02:09

CBroe