PHP code example of zjkal / mysql-helper

1. Go to this page and download the library: Download zjkal/mysql-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zjkal / mysql-helper example snippets


use zjkal\MysqlHelper;

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

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

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

//导出数据库(包含表结构和数据)
$mysql->exportSqlFile('test.sql');

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

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

//导出数据库所有表,并且添加禁用外键检查的SQL语句
$mysql->exportSqlFile('test.sql', true, [], true);
//php8以上可以更简洁的写法:
$mysql->exportSqlFile('test.sql', disableForeignKeyChecks: true);

//导入数据库
$mysql->importSqlFile('test.sql');

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