how to import sql file in mysql database using php

Solutions on MaxInterview for how to import sql file in mysql database using php by the best coders in the world

showing results for - "how to import sql file in mysql database using php"
Niclas
29 Feb 2016
1<?php
2$conn =new mysqli('localhost', 'root', '' , 'blog_samples');
3
4$query = '';
5$sqlScript = file('database-script.sql');
6foreach ($sqlScript as $line)	{
7	
8	$startWith = substr(trim($line), 0 ,2);
9	$endWith = substr(trim($line), -1 ,1);
10	
11	if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') {
12		continue;
13	}
14		
15	$query = $query . $line;
16	if ($endWith == ';') {
17		mysqli_query($conn,$query) or die('<div class="error-response sql-import-response">Problem in executing the SQL query <b>' . $query. '</b></div>');
18		$query= '';		
19	}
20}
21echo '<div class="success-response sql-import-response">SQL file imported successfully</div>';
22?>
queries leading to this page
import file in database mysqlphp code mysql load sql from filephp import sql fileimport a sql file to a database with phpphp mysql filehow to upload sql file in mysqlphp mysql how to import dataphp export mysql to sql filehow to import sql file to mysql with phphow to add sql file in phphow to import sql file using phpmysql import table in databasephp import sql file into databaseexport mysql database sql file using phphow to import sql into phpphp mysql exe import sql filehow to import database in mysql in phphow to import data from database to phpmysql import sql file to specific database phpimport from database phimport sql data from database phpimport database mysql using phpimport database from phpphp mysql open local sql fileimport database phpimport data from database phpphp query sql fileimport sql file to database in phpimport sql into phpphp import mysql dumphow import sql phpphp ile sql importimport sql file phphow to upload sql to database phphow to import a php databasephp sql fileimport sql file in mysql using phpphp mysql import sql fileimporting sql via phpimport sql file in mysql phpphp create and import mysql databaseget php to run and sql file to import into dbimport database using php scriptinclude database in phpphp import data from sqlphp import data to mysql databaseimport data at sql phpimport database using phpphp execute mysql filehow to use sql file as database in phpphp execute mysql importcreate php database and import sqlsql file import in db phpphp import mysql database connectionimport database in phpget sql file from site using phpload sql file into phpimport sql in php libraryphp code to import data from sql to mysqlmysql import sql file use phpphp code import sql using phphow to import database in phpphp import database to mysqlmysql php importphp import sql file to databaseimport sql file on phpphp import sqlimport sql file from phphow to import a sql file in phpphp import database from sql fileimport sql file with phpphp import file to databasehow to import mysql database using php codehow to connect sql file to phpimport sql in mysql serverupload database by phpcodeimport to mysql using phpexecelhow to import a file in a php databasephp import from db filehow to import sql file in mysql database using phphow to import sql file in mysql database using php