如何使用PDO在PHP中绑定bigint值?

如何使用PDO在PHP中绑定bigint值?,php,postgresql,pdo,bindvalue,Php,Postgresql,Pdo,Bindvalue,我在PostgreSQL数据库中有一列是bigint 到目前为止,我还无法找到一种在PHP中构造PDO插入的方法 仅列出PDO::PARAM_INT。当我在语句中使用它时,我得到以下错误。注意,即使在bindValue语句中没有包含数据类型,也会出现相同的错误。据我所知,通过省略类型,PHP正在基于变量类型使用PDO::PARAM_INT 未捕获异常“PDOException”,消息为“SQLSTATE[22003]:数值超出范围:7错误:值“2978878”;超出index.php:163中整

我在PostgreSQL数据库中有一列是bigint

到目前为止,我还无法找到一种在PHP中构造PDO插入的方法

仅列出
PDO::PARAM_INT
。当我在语句中使用它时,我得到以下错误。注意,即使在
bindValue
语句中没有包含数据类型,也会出现相同的错误。据我所知,通过省略类型,PHP正在基于变量类型使用
PDO::PARAM_INT

未捕获异常“PDOException”,消息为“SQLSTATE[22003]:数值超出范围:7错误:值“2978878”;超出index.php:163中整型“”的范围

这是一个关于同一问题的问题。但是,它们直接使用字符串作为数据库列类型。虽然这是一个很好的解决方法,但如果您无法更改数据库类型,则不考虑这一点

有没有一种在PHP中使用bigint和PDO的方法不需要修改数据库

示例代码

$query  =   "INSERT INTO clients ";
$query  .=  "(timestamp, name, value) ";
$query  .=  "VALUES (now(), :name, :value) ";
$query  .=  "RETURNING id";

$name = "Bob Probert";
$value = 2978878787878787878; // note this is less than bigint max of 9223372036854775807

$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->bindValue(':value', $value, PDO::PARAM_INT);
                                                           Table "db.clients"
    Column     |            Type             |                      Modifiers                       | Storage  | Stats target | Description 
---------------+-----------------------------+------------------------------------------------------+----------+--------------+-------------
 id            | integer                     | not null default nextval('tickets_id_seq'::regclass) | plain    |              | 
 timestamp     | timestamp without time zone |                                                      | plain    |              | 
 name          | character varying(40)       |                                                      | extended |              | 
 value         | bigint                      | not null                                             | plain    |              | 
Indexes:
    "tickets_pkey" PRIMARY KEY, btree (id)
表格

$query  =   "INSERT INTO clients ";
$query  .=  "(timestamp, name, value) ";
$query  .=  "VALUES (now(), :name, :value) ";
$query  .=  "RETURNING id";

$name = "Bob Probert";
$value = 2978878787878787878; // note this is less than bigint max of 9223372036854775807

$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->bindValue(':value', $value, PDO::PARAM_INT);
                                                           Table "db.clients"
    Column     |            Type             |                      Modifiers                       | Storage  | Stats target | Description 
---------------+-----------------------------+------------------------------------------------------+----------+--------------+-------------
 id            | integer                     | not null default nextval('tickets_id_seq'::regclass) | plain    |              | 
 timestamp     | timestamp without time zone |                                                      | plain    |              | 
 name          | character varying(40)       |                                                      | extended |              | 
 value         | bigint                      | not null                                             | plain    |              | 
Indexes:
    "tickets_pkey" PRIMARY KEY, btree (id)

我不知道这在PostgreSQL中是否有效,但对于MySQL,将这些值绑定为字符串是否有效。

我不知道这在PostgreSQL中是否有效,但对于MySQL,将这些值绑定为字符串是否有效。

您确定这是数据库中的一个BIGINT吗?你能显示你的表模式吗?@aynber+1,异常提到整数类型,而不是bigint,因为中的
字段超出了integer类型的范围。这告诉你,你的数据类型是
INT
而不是添加到原始帖子中的
bigint
。可能有助于了解一些事情。您是否使用64位硬件?操作系统是64位的吗?你的php版本是什么?echo PHP_INT_MAX;给你?你确定它是你数据库中的一个BIGINT吗?你能显示你的表模式吗?@aynber+1,异常提到整数类型,而不是bigint,因为
中的
字段超出了integer类型的范围。这告诉你,你的数据类型是
INT
而不是添加到原始帖子中的
bigint
。可能有助于了解一些事情。您是否使用64位硬件?操作系统是64位的吗?你的php版本是什么?echo PHP_INT_MAX;给你什么?