中文 | English
MysqlHelper
is a convenient tool to import and export Mysql database table structure and data with PHP
, which can quickly realize the import and export of mysql database.
- Easy to use: only depends on
mysqlli
extension,out of the box
- Flexible operation: Compatible with mainstream frameworks, more convenient to use
- Long-term maintenance: The author is a freelancer committed to ensuring the project's
long-term stability
andcontinuous updates
.
Install via Composer.
composer require zjkal/mysql-helper
Method 1: Conventional method
use zjkal\MysqlHelper;
$mysql = new MysqlHelper('root', 'root', 'testdatabase', '127.0.0.1', '3306', 'utf8mb4', 'wp_');
Method 2: After instantiation, set the database configuration through the setConfig method
$mysql = new MysqlHelper();
$mysql->setConfig(['username' => 'root', 'password' => 'root', 'database' => 'testdatabase']);
MysqlHelper is compatible with commonly used frameworks, you can directly use the database configuration of the framework, such as ThinkPHP
framework or Laravel
framework
$mysql = new MysqlHelper();
$config = config('database.connections.mysql');
$mysql->setConfig($config);
//Export database (including table structure and data)
$mysql->exportSqlFile('test.sql');
//Export only the database table structure
$mysql->exportSqlFile('test.sql', false);
//Export the structure and data of the specified table
$mysql->exportSqlFile('test.sql', true, ['table1', 'table2']);
- The table prefix in the sql file needs to be replaced by
__PREFIX__
placeholder - If the database prefix has been set during instantiation, you do not need to pass in the second parameter
import database
$mysql->importSqlFile('test.sql');
//Import the database and automatically replace the table prefix
$mysql->importSqlFile('test.sql', 'wp_');
v1.0.3 Dec 9, 2023
- If a table prefix is set during instantiation, the exported table name can not contain the prefix
v1.0.2 Sep 23, 2023
- Increased export stability
v1.0.1 Sep 10, 2023
- Fixed the bug of incorrect port recognition under the Thinkphp framework
- Increased import stability
v1.0.0 Sep 2, 2023
- Initial Release
The MIT License (MIT). Please see License File for more information.