💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Coroutine\PostgreSQL->query postgresql发送异步非阻塞 协程命令 ```php function Coroutine\PostgreSQL->query(resource $connection); ``` example: ```php go(function () { $pg = new Swoole\Coroutine\PostgreSQL(); $conn = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=root password="); $result = $pg -> query('SELECT * FROM test;'); $arr = $pg -> fetchAll($result); var_dump($arr); }); ``` 返回insert id: ```php go(function () { $pg = new Swoole\Coroutine\PostgreSQL(); $conn = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=wuzhenyu password="); $result = $pg -> query("insert into test (id,text) VALUES (24,'text') RETURNING id ;"); $arr = $pg -> fetchRow($result); var_dump($arr); }); ?> ``` 也可以多次提交query 命令 ,如begin commit ```php go(function () { $pg = new Swoole\Coroutine\PostgreSQL(); $conn = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=root password="); $pg -> query('BEGIN;'); $result = $pg -> query('SELECT * FROM test;'); $arr = $pg -> fetchAll($result); $pg -> query('COMMIT;'); var_dump($arr); }); ```