自带的mysql为什么插入成功,但是返回的0?

a1747699213

$insertId = self::$conn->insert($this->table)->cols($data)->query();

echo $insertId;

数据库里面已经有数据了,但是这个始终是返回0

2384 1 0
1个回答

a1747699213

解决了。是因为我表的主键是创建的全球ID,不是自增ID。

建议如下解决:
在官方的文件\workerman\mysql\src\Connection.php第1838行,源代码如下。
if ($this->sQuery->rowCount() > 0) {
return $this->lastInsertId();
}

修改为:
if ($this->sQuery->rowCount() > 0) {
if( $this->lastInsertId() == 0 )
{
return true;
}
return $this->lastInsertId();
}

  • 暂无评论
年代过于久远,无法发表回答
🔝