duanran8648 2015-09-22 11:46
浏览 30
已采纳

SQL查询不返回预期值。 PHP - MYSQL

$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?

  • 写回答

2条回答 默认 最新

  • douyue2313 2015-09-22 13:24
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)