php PDO::PARAM 用于十进制类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2718628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PDO::PARAM for type decimal?
提问by dmontain
I have 2 database fields
我有 2 个数据库字段
`decval` decimal(5,2)
`intval` int(3)
I have 2 pdo queries that update them. The one that updates the int works ok
我有 2 个 pdo 查询来更新它们。更新 int 的那个工作正常
$update_intval->bindParam(':intval', $intval, PDO::PARAM_INT);
but I can't update the decimal field. I've tried the 3 ways below, but nothing works
但我无法更新小数字段。我已经尝试了以下 3 种方法,但没有任何效果
$update_decval->bindParam(':decval', $decval, PDO::PARAM_STR);
$update_decval->bindParam(':decval', $decval, PDO::PARAM_INT);
$update_decval->bindParam(':decval', $decval);
It seems the problem is with the database type decimal? Is there a PDO::PARAMfor a field of type decimal? If not, what do I use as a workaround?
似乎问题出在数据库类型上decimal?是否有PDO::PARAMfor 类型的字段decimal?如果没有,我使用什么作为解决方法?
回答by Alix Axel
There isn't any PDO::PARAMfor decimals / floats, you'll have to use PDO::PARAM_STR.
没有任何PDO::PARAM小数/浮点数,您必须使用PDO::PARAM_STR.
回答by Gil
UP must use the PDO::PARAM_STR same, and noting that if the column in the database is of type NUMERIC (M, D) or decimal (M, D) should be observed that the M is the number of characters precision should be the total of characters that you can enter, and D the number of decimal places. In the example NUMERIC (10,2) we have 8 houses to places of accuracy and two decimal places. So we have 10 characters in total with 2 reserved for decimal places.
UP 必须使用 PDO::PARAM_STR 相同,并注意如果数据库中的列是 NUMERIC (M, D) 或十进制 (M, D) 类型,则应注意 M 是字符数,精度应为您可以输入的字符总数,以及 D 小数位数。在示例 NUMERIC (10,2) 中,我们有 8 个宫位精度和两位小数。所以我们总共有 10 个字符,其中 2 个保留给小数位。
回答by julio castillo
I found a solution, send the decimal parameter like PDO::PARAM_STR, in the sql server store procedure receive it like decimal(int,dec)
我找到了一个解决方案,发送像PDO::PARAM_STR这样的decimal参数,在sql server存储过程中像decimal(int,dec)一样接收它
PHP
PHP
$stmt_e->bindParam(':valor_escala_desde', $valor_escala_desde, PDO::PARAM_STR);
SQL SERVER, STORE PROCEDURE:
SQL 服务器,存储过程:
@valor_escala_desde decimal(18,2),
and is done.
并完成。
回答by Paul Kiarie
use PDO::PARAM_STR for all column types which are not of type int or Bool
对所有非 int 或 Bool 类型的列类型使用 PDO::PARAM_STR

