Mic*_*ael 8 php postgresql pdo lastinsertid
我正在使用Postgresql,当我想使用PDO检索最新的插入ID时,我遇到了问题.这是我的代码:
$db->lastInsertId('columnName');
Run Code Online (Sandbox Code Playgroud)
错误消息说
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "columnName" does not exist
Run Code Online (Sandbox Code Playgroud)
我想我对PHP手册中陈述的"序列对象"有一些误解.
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.
Run Code Online (Sandbox Code Playgroud)
目前,"columnName"是该自动递增属性的字符串.任何人都可以指出我哪里出错了吗?谢谢.
mu *_*ort 17
PostgreSQL使用序列为serial列生成值,列serial通常用于PostgreSQL中的"自动递增"列.序列具有名称,并且通常独立于任何特定表,因此您可以使用一个序列为多个不同的表生成唯一ID; 序列名称是lastInsertId它的参数:
例如,PDO_PGSQL()要求您为name参数指定序列对象的名称.
PostgreSQL创建的序列对象自动命名[table]_[column]_seq,所以:
$id = $db->lastInsertId('tableName_columnName_seq');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8867 次 |
| 最近记录: |