我使用的是 Postgresql,当我想使用 PDO 来检索最新的插入 ID 时,我遇到了问题.这是我的代码:
I am using Postgresql, when I want to use PDO to retrieve the latest insertion ID, I got a problem. Here is my code:
$db->lastInsertId('columnName');
错误信息说
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "columnName" does not exist
我想我对 PHP 手册中所述的序列对象"有些误解.
I guess I have some misunderstanding about "sequence object" stated in the PHP Manual.
Note:
Returns the ID of the last inserted row, or the last value from a sequence object,
depending on the underlying driver. For example, PDO_PGSQL() requires you to specify the
name of a sequence object for the name parameter.
目前,columnName"是该自增属性的字符串.谁能指出我哪里出错了?谢谢.
Currently, the "columnName" is the string of that auto-incremented attribute. Can anyone point out where I went wrong? Thanks.
PostgreSQL 使用 序列 为serial 列和 serial 列通常用于 PostgreSQL 中的自动递增"列.序列有名称,并且通常独立于任何特定的表,因此您可以使用一个序列为多个不同的表生成唯一的 ID;序列名称是 lastInsertId 想要作为其参数的名称:
PostgreSQL uses sequences to generate values for serial columns and serial columns are generally what is used for "auto-incrementing" columns in PostgreSQL. Sequences have names and are, in general, independent of any particular table so you could have one sequence generating unique IDs for several different tables; the sequence name is what lastInsertId wants as its argument:
例如,PDO_PGSQL() 要求您为 name 参数指定序列对象的名称.
For example, PDO_PGSQL() requires you to specify the name of a sequence object for the name parameter.
PostgreSQL创建的序列对象自动命名为[table]_[column]_seq,所以:
The sequence object created by PostgreSQL is automatically named [table]_[column]_seq, So:
$id = $db->lastInsertId('tableName_columnName_seq');
这篇关于lastInsertId 在 Postgresql 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)