MySQL is a popular Linux-based database program. As a database, MySQL is a versatile application. It can be used for something as simple as a product database, or as complex as a Wordpress website..
This package will help you Export a MySQL database and Import it from a dump file in PHP.
- Export MySQL database and Tables to a file (.sql)
- Import it from a file
See SQLITE Export And Import LIbraray for SQLITE DB EXport and Import
This Library requires PHP to run.
$ composer require vwedesam/mysql-export-import
using helper function mysqlExporter" and MysqlImporter with connection "params"
require "../vendor/autoload.php";
$host = "localhost";
$user = "root";
$pass = "";
$name = "my_mysql_db";
// Connection Parameters
$connection_params = [
'host' => $host,
'name' => $name,
'user' => $user,
'pass' => $pass
];
// parameters
// 1: Mysql database Instance <instance>
// 2. mysql tables to be export <Array>
// 3. backup name <String>
// 4. connection parameters <Array>
MysqlExporter(null, ['products'], false, $connection_params);
// parameters
// 1: Mysql database Instance <instance>
// 2. full path eg "../filepath/db.sql" to mysql dump file (.sql, .zip)
// 3. connectoin params <Array>
MysqlImporter(null, $sql_content, $connection_params);
// return: true / false
using helper function mysqlExporter and MysqlImporter with "Mysql Instance"
require "../vendor/autoload.php";
$host = "localhost";
$user = "root";
$pass = "";
$name = "my_mysql_db";
$dsn = "mysql:dbname=$name;host=$host";
// PDO instance
$db_instance = new \PDO($dsn, $user, $pass);
MysqlExporter($db_instance);
MysqlImporter($db_instance, $sql_content);
// return: true / false
Mysql Export Import with classes, functions and connection params
MIT