php&中最大数量的目的MySQL的 [英] purpose of the max number in php & mysql

查看:62
本文介绍了php&中最大数量的目的MySQL的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在php和mysql中,最大数量限制的主要目的是什么?
这是否意味着我们可以/不能处理或存储大于限制的数字?

What is the main purpose for the maximum limit for number in php and mysql?
Does this means that we can/cannot process or store numbers that is larger than the limit?

我回显PHP_INT_MAX,并显示2147483647.

我乘以1000000000000000000000并得到像2.147483647E+30这样的答案,我认为它已经超出限制了?

I multiply by 1000000000000000000000 and get answers like 2.147483647E+30 which i think is already over the limit?

请告知.

非常感谢您的指导.

当我考虑验证用户表单输入时,会出现此问题.我想确保用户输入的内容符合我们定义的数字格式,而不是其他内容.
然后,我在网上进行了一些最佳实践的搜索,并意识到了这个限制",但是不知道在使用PHP& PHP时如何正确处理它. MYSQL.请告知:

This question arise when I'm thinking about validating the user form input. I want to make sure that the user input is according to our defined number format and not something else.
Then i do some online search for best practices and come to aware of this "limits" but do not know how to handle it correctly when using PHP & MYSQL. Pls advise:

第1步:修整并将用户表单输入的字符串编号"转换为数字.
步骤2:验证数字为正整数格式.
步骤3:验证数字不超过我的最大限制".
由于PHP限制(2,147,483,647)小于mysql限制(18,446,744,073,709,500,000)?我将php作为最大限制.
步骤4:执行一些计算...
第5步:验证我的结果不超过我的最大限制.
步骤6:将结果存储在mysql中.

Step 1: trim and convert user form input "string number" to number.
Step 2: validate the number is in positive integer format.
Step 3: validate the number does not exceed my "max limit".
Since php limit (2,147,483,647) is smaller than mysql limit (18,446,744,073,709,500,000)? i'll take php as my max limit.
Step 4: perform some calculations...
Step 5: validate my result does not exceed my max limit.
Step 6: store the result in mysql.

推荐答案

这是CPU的硬件限制.您仍然可以使用 bc数学函数处理较大的数字.在mysql中,它是关于对齐字节的,因此它知道哪一偏移量是哪一列.

It's hardware limit of the CPU. You can still use bc math function to work with larger numbers. In mysql it is about aligning bytes, so it knows at which offset is which column.

乘法结果将转换为 float .

这篇关于php&中最大数量的目的MySQL的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆