1 Star 3 Fork 0

zjkal / mysql-helper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

MysqlHelper

中文 | English

License PHP Version Require Latest Stable Version Total Downloads GitHub Workflow Status

MysqlHelper 是一个便捷的通过PHP导入和导出Mysql数据库表结构和数据的工具,可以快速实现mysql的数据库的导入和导出.

🧩特性

  • 简单易用: 仅依赖mysqlli扩展,开箱即用
  • 灵活操作: 兼容主流框架,使用更方便
  • 长期维护: 作者为自由职业者,保证项目的长期稳定持续更新

🚀安装

通过Composer导入类库

composer require zjkal/mysql-helper

🌈使用文档

1. 实例化

方式一: 常规方法

use zjkal\MysqlHelper;

$mysql = new MysqlHelper('root', 'root', 'testdatabase', '127.0.0.1', '3306', 'utf8mb4', 'wp_');

方式二: 实例化后,通过setConfig方法设置数据库配置

$mysql = new MysqlHelper();
$mysql->setConfig(['username' => 'root', 'password' => 'root', 'database' => 'testdatabase']);

MysqlHelper针对常用的框架做了兼容,可以直接使用框架的数据库配置, 比如ThinkPHP框架或Laravel框架

$mysql = new MysqlHelper();
$config = config('database.connections.mysql');
$mysql->setConfig($config);

2. 导出数据

  • 如果实例化时, 已经设置了表前缀,导出的表名可以不用带前缀
//导出数据库(包含表结构和数据)
$mysql->exportSqlFile('test.sql');

//仅导出数据库表结构
$mysql->exportSqlFile('test.sql', false);

//导出指定表的结构和数据
$mysql->exportSqlFile('test.sql', true, ['table1', 'table2']);

3. 导入数据

  • sql文件中的表前缀需要使用__PREFIX__占位符代替
  • 如果实例化时,已经设置了表前缀,则可以不用传入第二个参数
//导入数据库
$mysql->importSqlFile('test.sql');

//导入数据库,并自动替换表前缀
$mysql->importSqlFile('test.sql', 'wp_');

📃更新日志

v1.0.4 2024年4月19日

  • 优化了.sql文件中注释的过滤规则

v1.0.3 2023年12月9日

  • 实例化时如果已经设置了表前缀,导出的表名可以不包含前缀

v1.0.2 2023年9月23日

  • 增加了数据导出的稳定性

v1.0.1 2023年9月10日

  • 修复了在Thinkphp框架下端口识别错误的BUG
  • 增加了导入的稳定性

v1.0.0 2023年9月2日

  • 首次发布

🐧QQ频道

📖开源协议

MysqlHelper遵循MIT开源协议, 意味着您无需任何授权, 即可免费将MysqlHelper应用到您的项目中

MIT License Copyright (c) 2023 zjkal Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个便捷的MySQL导入导出的助手类库。 a mysql import and export helper library. 展开 收起
PHP
MIT
取消

发行版 (5)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/zjkal/mysql-helper.git
git@gitee.com:zjkal/mysql-helper.git
zjkal
mysql-helper
mysql-helper
main

搜索帮助