big database file into database php

Solutions on MaxInterview for big database file into database php by the best coders in the world

showing results for - "big database file into database php"
Mattia
17 Aug 2016
1<?php
2
3// Name of the file
4$filename = 'churc.sql';
5// MySQL host
6$mysql_host = 'localhost';
7// MySQL username
8$mysql_username = 'root';
9// MySQL password
10$mysql_password = '';
11// Database name
12$mysql_database = 'dump';
13
14// Connect to MySQL server
15mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
16// Select database
17mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());
18
19// Temporary variable, used to store current query
20$templine = '';
21// Read in entire file
22$lines = file($filename);
23// Loop through each line
24foreach ($lines as $line)
25{
26// Skip it if it's a comment
27if (substr($line, 0, 2) == '--' || $line == '')
28    continue;
29
30// Add this line to the current segment
31$templine .= $line;
32// If it has a semicolon at the end, it's the end of the query
33if (substr(trim($line), -1, 1) == ';')
34{
35    // Perform the query
36    mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
37    // Reset temp variable to empty
38    $templine = '';
39}
40}
41 echo "Tables imported successfully";
42?>
43