Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

示例有点问题 #1

Open
c2498168786 opened this issue Jun 21, 2021 · 1 comment
Open

示例有点问题 #1

c2498168786 opened this issue Jun 21, 2021 · 1 comment

Comments

@c2498168786
Copy link

$connection = $this->pgsql->createConnection();
return $connection->select("SELECT * FROM test WHERE testid = AND testname = ;", array($id, $name));

这示例是错的,因为这个底层使用的是Coroutine\PostgreSQL

所以应该这样写:
$connection = $this->pgsql->createConnection();
return $connection->select("SELECT * FROM test WHERE testid = $1 AND testname = $2;", array($id, $name));

@c2498168786
Copy link
Author

c2498168786 commented Jul 5, 2021

\vendor\curtis18\swoft-pgsql\src\Connection\Connection.php 68行

$this->client->close();会报错,会说Swoole\Coroutine\PostgreSQL 没有close方法。会导致连接不能关闭。用连接池就会有问题。

所以解决如下:
$this->client = null; // 制空 底层会自动回收,使用了引用计数计

问题二:\vendor\curtis18\swoft-pgsql\src\Connection\Connection.php 171行
$hash = md5($query); // 当开启事务。并且事务里面进行循环的分片插入。会出错 current transaction is aborted, commands ignored until end of transaction block

        $prepare = $this->client->prepare("query_".$hash, $query);
        $resource = $this->client->execute("query_".$hash, $bindings);

解决办法:
$hash = 采用名称唯一值解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant