The question is published on by Tutorial Guruji team.
$uid=intval($_GET['uid']); //98765432109876543 $sql = "SELECT * FROM accounts WHERE uid = $uid ORDER BY id DESC LIMIT 1";
Won’t return any result, PHP is 64bit.
Below I put the executed commands from mysql client. uid field is BIGINT
Output from the mysql client: mysql> SELECT * FROM accounts WHERE id = 1 ORDER BY id DESC LIMIT 1; | id | uid | paid_date | | 1 | 98765432109876543 | 2015-09-20 12:56:47 |
—
Output from the mysql client: mysql> SELECT * FROM accounts WHERE uid=98765432109876543 ORDER BY id DESC LIMIT 1; Empty set (0.00 sec)
So my question is, what is the reason I cannot retrieve the expected value from the first sql query?
Answer
I’ve executed your quires, just worked fine for me. You need to update your table schema
.
I’ve tested with some thing like these.
First, I’ve create a table
with uid
as VARCHAR(50)
, and it returned fine results.
Check this Fiddle.
but what if you want uid
as INT
? you can’t use INT
to store more than 10 or 11 char long string(integer) because it ranges from -2147483648
to 2147483647
and for UNSIGNED INT
ranging from 0
to 4294967295
.
So you’ve to use BIGINT
instead, it ranges from -9223372036854775808
to 9223372036854775807
. Check this FIDDLE.
I assume that uid
will never have value in -ve, so use BIGINT UNSIGNED
, it ranges from 0
to 18446744073709551615
and that will also work for you.
Check this FIDDLE
To read more about limitations/ranges, please look here
Hope this will help you.