PHP version of psql cli that comes with PostgreSQL
MIT License
psql
in PHPPHP light version of psql
that comes with PostgreSQL.
pg_dump --inserts
dumppsql
clientSpeed is exactly the same of the original psql
binary thanks to streams usage.
Input type | Example | Supported? |
---|---|---|
pg_dump output (with COPY commands) |
as is | ❌ |
pg_dump --inserts output |
as is | ✔️ |
Single query on single line | SELECT NOW(); |
✔️ |
Single query on multiple lines |
SELECT NOW();
|
✔️ |
Multiple queries on separated single or multiple lines |
SELECT NOW(); SELECT NOW();
|
✔️ |
Multiple queries on single line | SELECT NOW();SELECT NOW(); |
❌ |
When using pg_dump --inserts
it is highly recommended to also set --rows-per-insert=1000
to speed performances up.
The library provides two usages, the binary and the \SlamPsql\Psql
class.
$ ./psql -h
Usage: psql [OPTIONS]
--host Connect to host
--port Port number
--username User for login
--password Password to use
--database Database to use
--connect_timeout Connect timeout to use
$ printf "CREATE DATABASE foobar;\nSELECT datname FROM pg_database;" | ./psql
foobar
$ ./psql --database foobar < foobar_huge_dump.sql
$psql = new \SlamPsql\Psql('localhost', 5432, 'my_username', 'my_password', 'my_database');
$return = $psql->run(\STDIN, \STDOUT, \STDERR);
exit((int) (true !== $return));
// With the connect_timeout argument
$psql = new \SlamPsql\Psql('localhost', 5432, 'my_username', 'my_password', 'my_database', 5);
$return = $psql->run(\STDIN, \STDOUT, \STDERR);
exit((int) (true !== $return));
\SlamPsql\Psql::run
accepts any type of resource consumable by fgets/fwrite
functions.