{"id":14973859,"url":"https://github.com/slamdunk/psql-php","last_synced_at":"2025-10-27T02:31:35.501Z","repository":{"id":192362175,"uuid":"686900551","full_name":"Slamdunk/psql-php","owner":"Slamdunk","description":"PHP version of psql cli that comes with PostgreSQL","archived":false,"fork":false,"pushed_at":"2024-05-01T18:19:10.000Z","size":81,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T21:28:14.069Z","etag":null,"topics":["php","postgresql","psql"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Slamdunk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Slamdunk"],"custom":"https://paypal.me/filippotessarotto"}},"created_at":"2023-09-04T07:28:46.000Z","updated_at":"2024-05-06T02:33:58.148Z","dependencies_parsed_at":"2024-05-06T02:43:59.305Z","dependency_job_id":null,"html_url":"https://github.com/Slamdunk/psql-php","commit_stats":null,"previous_names":["slamdunk/psql-php"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slamdunk%2Fpsql-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slamdunk%2Fpsql-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slamdunk%2Fpsql-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slamdunk%2Fpsql-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Slamdunk","download_url":"https://codeload.github.com/Slamdunk/psql-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219861939,"owners_count":16555980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","postgresql","psql"],"created_at":"2024-09-24T13:49:35.250Z","updated_at":"2025-10-27T02:31:35.158Z","avatar_url":"https://github.com/Slamdunk.png","language":"PHP","funding_links":["https://github.com/sponsors/Slamdunk","https://paypal.me/filippotessarotto"],"categories":[],"sub_categories":[],"readme":"# `psql` in PHP\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/slam/psql-php.svg)](https://packagist.org/packages/slam/psql-php)\n[![Downloads](https://img.shields.io/packagist/dt/slam/psql-php.svg)](https://packagist.org/packages/slam/psql-php)\n[![Integrate](https://github.com/Slamdunk/psql-php/workflows/CI/badge.svg?branch=master)](https://github.com/Slamdunk/psql-php/actions)\n[![Code Coverage](https://codecov.io/gh/Slamdunk/psql-php/coverage.svg?branch=master)](https://codecov.io/gh/Slamdunk/psql-php?branch=master)\n\nPHP light version of `psql` that comes with PostgreSQL.\n\n## Why\n\n1. You are inside a PHP only environment, like a PHP Docker image\n1. You need to import a large `pg_dump --inserts` dump\n1. You don't have access to the native `psql` client\n\n## Performance\n\nSpeed is exactly the **same** of the original `psql` binary thanks to streams usage.\n\n## Supported formats\n\n| Input type                                             | Example                                     |     Supported?     |\n|--------------------------------------------------------|---------------------------------------------|:------------------:|\n| `pg_dump` output (with `COPY` commands)                | *as is*                                     |        :x:         |\n| `pg_dump --inserts` output                             | *as is*                                     | :heavy_check_mark: |\n| Single query on single line                            | `SELECT NOW();`                             | :heavy_check_mark: |\n| Single query on multiple lines                         | `SELECT`\u003cbr /\u003e`NOW();`                      | :heavy_check_mark: |\n| Multiple queries on separated single or multiple lines | `SELECT NOW();`\u003cbr /\u003e`SELECT`\u003cbr /\u003e`NOW();` | :heavy_check_mark: |\n| Multiple queries on single line                        | `SELECT NOW();SELECT NOW();`                |        :x:         |\n\nWhen using `pg_dump --inserts` it is highly recommended to also set `--rows-per-insert=1000` to speed performances up.\n\n## Usage\n\nThe library provides two usages, the binary and the `\\SlamPsql\\Psql` class.\n\n### From CLI\n\n```\n$ ./psql -h\nUsage: psql [OPTIONS]\n  --host              Connect to host\n  --port              Port number\n  --username          User for login\n  --password          Password to use\n  --database          Database to use\n  --connect_timeout   Connect timeout to use\n\n$ printf \"CREATE DATABASE foobar;\\nSELECT datname FROM pg_database;\" | ./psql\nfoobar\n\n$ ./psql --database foobar \u003c foobar_huge_dump.sql\n```\n\n### From PHP\n\n```php\n$psql = new \\SlamPsql\\Psql('localhost', 5432, 'my_username', 'my_password', 'my_database');\n$return = $psql-\u003erun(\\STDIN, \\STDOUT, \\STDERR);\nexit((int) (true !== $return));\n\n// With the connect_timeout argument\n$psql = new \\SlamPsql\\Psql('localhost', 5432, 'my_username', 'my_password', 'my_database', 5);\n$return = $psql-\u003erun(\\STDIN, \\STDOUT, \\STDERR);\nexit((int) (true !== $return));\n\n```\n\n`\\SlamPsql\\Psql::run` accepts any type of resource consumable by `fgets/fwrite` functions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslamdunk%2Fpsql-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslamdunk%2Fpsql-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslamdunk%2Fpsql-php/lists"}