承接 slam/psql-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slam/psql-php

Composer 安装命令:

composer require slam/psql-php

包简介

PHP version of psql cli that comes with PostgreSQL

README 文档

README

Latest Stable Version Downloads Integrate Code Coverage

PHP light version of psql that comes with PostgreSQL.

Why

  1. You are inside a PHP only environment, like a PHP Docker image
  2. You need to import a large pg_dump --inserts dump
  3. You don't have access to the native psql client

Performance

Speed is exactly the same of the original psql binary thanks to streams usage.

Supported formats

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.

Usage

The library provides two usages, the binary and the \SlamPsql\Psql class.

From CLI

$ ./psql -h
Usage: psql [OPTIONS]
  -h, --host              Connect to host
  -p, --port              Port number
  -U, --username          User for login
  -d, --dbname            Database to use
	  --connect_timeout   Connect timeout to use, in seconds

  Use `PGPASSWORD` env variable to set the connection password.

$ printf "CREATE DATABASE foobar;\nSELECT datname FROM pg_database;" | ./psql
foobar

$ ./psql --database foobar < foobar_huge_dump.sql

From PHP

$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.

统计信息

  • 总下载量: 10.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固