在foreach我的表中插入数据,我需要有最后的ID插入。
林将第一实体,拿到编号,并插入一个孩子的实体,与此ID链接。
数据库POSTGRES - ENV的Symfony 4
代码:
$conn = $em->getConnection();
//Here i do an Insert ( always an INSERT )
$Id = $conn->lastInsertId('tableName_id_seq');
这回:不确定表:7 ERROR:关系“tableName_id_seq”不存在
我觉得我的顺序没有在DB中创建我不关闭Connexion公司前调用lastInsertID桃李lastInsertID前未插入
此查询:
select sequence_schema, sequence_name from information_schema.sequences;
返回0行
随着MySQL
你不需要提供tableName_id_seq
你可以尝试$Id = $conn->lastInsertId();
那么没有办法使用lastinsertId(),我发现我的方式使用
RETURNING id
在查询中,然后经过
$preparedQuery->execute()
我做了
$preparedQuery->fetchAll()