Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

PHP Import SQL from a .sql file

David Carr

Development Tools

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);

 

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.