Development, Tools

PHP Import SQL from a .sql file

I've released a new package to easily import a .sql file into a database using PDO.

To install the package import it using composer:

composer require daveismyname/sql-import

Or download and include import.php manually from https://github.com/daveismyname/sql-import

Then to use the library, define your database file path and credentials, the last option dropTables when set to true will delete all the tables in the database before import the sql file.

<?php
require('vendor/autoload.php');

use Daveismyname\SqlImport\Import;

$filename = 'database.sql';
$username = 'root';
$password = '';
$database = 'sampleproject';
$host = 'localhost';
$dropTables = true;
new Import($filename, $username, $password, $database, $host, $dropTables);

 

David Carr

David Carr

For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.

In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.

Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.