开发者

How to keep long int during PHP string conversion?

The following PHP code:

$someID = 124234454288758;
$queryStr => "SELECT a FROM b WHERE some_id = {$someID}";

is converted to:

"SELECT a FROM b WHERE some_id = 1.2423445428876E+14"

How can I get the result string as:

"SELECT开发者_运维百科 a FROM b WHERE some_id = 124234454288758"

Thanks!


Try this:

number_format($someID, 0, '.', '');

Reference: problems with big integers


Use GMP ( http://www.php.net/manual/en/book.gmp.php ) or BCMath ( http://www.php.net/manual/en/book.bc.php ) when dealing with very large numbers.


Since your not doing any math with the number (since it's just a unique key), why not just store it as a string.

$someID = "124234454288758";

Also, it's worth mentioning that SQL query creation like that is often open to SQL injection. You should probably consider using PDO and it's prepare functionality.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜