slam / mysql-php
PHP version of mysql cli that comes with MySQL
Fund package maintenance!
Slamdunk
paypal.me/filippotessarotto
Installs: 23 303
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 0
Open Issues: 4
Requires
- php: ~8.1.0 || ~8.2.0
- ext-mysqli: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13.2
- phpstan/phpstan: ^1.9.6
- phpstan/phpstan-phpunit: ^1.3.3
- phpstan/phpstan-strict-rules: ^1.4.4
- phpunit/phpunit: ^9.5.27
This package is auto-updated.
Last update: 2024-10-20 16:31:24 UTC
README
PHP light version of mysql cli that comes with MySQL.
Why
- You are inside a PHP only environment, like a PHP Docker image
- You need to import a large mysql dump
- You don't have access to the native
mysql
client
Performance
Speed is exactly the same of the original mysql
binary thanks to streams usage.
Supported formats
Usage
The library provides two usages, the binary and the \SlamMysql\Mysql
class.
From CLI
$ ./mysql -h
Usage: mysql [OPTIONS]
--host Connect to host [Default: INI mysqli.default_host]
--port Port number [Default: INI mysqli.default_port]
--username User for login [Default: INI mysqli.default_user]
--password Password to use [Default: INI mysqli.default_pw]
--database Database to use [Default: empty]
--socket The socket file [Default: INI mysqli.default_socket]
$ printf "CREATE DATABASE foobar;\nSHOW DATABASES;" | ./mysql
information_schema
foobar
mysql
performance_schema
sys
$ ./mysql --database foobar < foobar_huge_dump.sql
From PHP
$mysql = new \SlamMysql\Mysql('localhost', 'root', 'pwd', 'my_database', 3306, '/socket'); $return = $mysql->run(\STDIN, \STDOUT, \STDERR); exit((int) (true !== $return));
\SlamMysql\Mysql::run
accepts any type of resource consumable by fgets/fwrite
functions.
Related projects
- ifsnop/mysqldump-php:
mysqldump
binary port in pure PHP