shpasser / GaeSupportL5

Google App Engine Support package for Laravel 5
MIT License
160 stars 27 forks source link

Database Query #43

Closed faifai0429 closed 8 years ago

faifai0429 commented 8 years ago

I have my primiary key (user_id) set to be auto_increment and the datatype is a bigint, 20bits. However, when I fetch records from database, it is truncated to something else.

The user_id in database is 190000000001(12 digits) but when I do exit(var_dump(Auth::user())) after Auth::attempt([....]) in AuthController.php, the user_id is truncated to something 9 digits like 109876541.

faifai0429 commented 8 years ago

Please advise

shpasser commented 8 years ago

Please supply me a sample app demonstrating the issue and I will take it from there.

shpasser commented 8 years ago

I am going to wait 3 day for your reply and then close the issue if no reply arrives.

faifai0429 commented 8 years ago

I have a table called 'users' and with a primiary key column called 'user_id', bigint(20).

The app is nothing but just two lines: $users = DB::tables('users')->get(); var_dump($users);

And you will see the user id is actually truncated or becomes negative number (overflow).

shpasser commented 8 years ago

Ok, please send me your migration file, so I could create the table on my app. BTW, what happens if you run the same code on homestead VM?

Sent from my iPhone

On Jan 5, 2016, at 3:52 AM, faifai0429 notifications@github.com wrote:

I have a table called 'users' and with a primiary key column called 'user_id', bigint(20).

The app is nothing but just two lines: $users = DB::tables('users')->get(); var_dump($users);

And you will see the user id is actually truncated or becomes negative number (overflow).

— Reply to this email directly or view it on GitHub.

faifai0429 commented 8 years ago

In fact, I did not use homestead and migration. There is nothing else but the problem mentioned above. What you can do is simply create a table and set the primary key column to be bigint(20) and insert one row having the id more than 11digits. After that, just fetch it using query builder see the result.

Interestingly, no such id problem for running gae in local. My machine is a 64bit machine.

shpasser commented 8 years ago

First of all bigint(20) is does not mean 20bits, the size of MySQL's bigint is 64bits (8 bytes). You can see it for yourself: https://dev.mysql.com/doc/refman/5.5/en/integer-types.html

20 indicates the maximum display width: https://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html

Since you have a 64bit machine PHP has 64bit int you can the the original 64bit value, on the other hand your GAE instance has 32bit int and this is the reason for the truncation. To display full ids you will have to somehow convert your ids to strings inside CloudSQL before it arrives to PHP or figure something else.

faifai0429 commented 8 years ago

The problem is, this is caused by laravel since I have no problem using PDO which I did nothing with the CloudSQL.

shpasser commented 8 years ago

Please take a look at the following: http://stackoverflow.com/questions/16374568/php-mysql-bigint-issue

Looks like you are not the only one...

As I see, the issue is not caused by Laravel or by my package. Anyway, as of now, size of int on GAE is 32bit.

Sent from my iPhone

On Jan 6, 2016, at 11:32 AM, faifai0429 notifications@github.com wrote:

The problem is, this is caused by laravel since I have no problem using PDO which I did nothing with the CloudSQL.

— Reply to this email directly or view it on GitHub.

faifai0429 commented 8 years ago

I am still confusing. Under the same server, i.e GAE, using pure php pdo query vs laravel's query makes different result. The former one does not truncate the number, but the later one does.