dcblogdev/sql-import

Import .sql file into a database using PDO

Fund package maintenance!
dcblogdev

v2.0.1 2022-12-28 01:08 UTC

This package is auto-updated.

Last update: 2024-10-28 05:04:57 UTC


README

Latest Version on Packagist Total Downloads

Logo

PDO import sql from a .sql file

Install

Using composer include the repository by typing the following into a terminal

composer require dcblogdev/sql-import

Usage

Include the composer autoloader, import the Import namespace.

Define your database file path and credentials, the option dropTables, when set to true, will delete all the tables in the database before the sql file gets imported.

The option forceDropTables is optional and not recommended. When enabled together with dropTables, the deletion of tables will be executed with disabled foreign key checks. Only use this method if you are sure that the integrity of the existing data in the database does not matter.

use Dcblogdev\SqlImport\Import;

$filename = 'database.sql';
$username = 'root';
$password = '';
$database = 'sampleproject';
$host = 'dev';
$dropTables = true;
$forceDropTables = false;

new Import($filename, $username, $password, $database, $host, $dropTables, $forceDropTables);