<?php
//echo "<pre>";print_r($_SERVER);exit;
$script_path = $_SERVER["DOCUMENT_ROOT"]."/sms/database";
/*
$vals['db_user'] = "mssinfot_sms"; 
$vals['db_pass'] = "123@qwe"; 
$vals['db_host'] = "localhost"; 
$vals['db_name'] = "mssinfot_sms";

$command = "mysql -u{$vals['db_user']} -p{$vals['db_pass']} "
 . "-h {$vals['db_host']} -D {$vals['db_name']} < {$script_path}";

$output = shell_exec($command . '/sql.sql');
echo $output;

$mysql_host = "localhost";
$mysql_database = "mssinfot_sms";
$mysql_user = "mssinfot_sms";
$mysql_password = "123@qwe";
# MySQL with PDO_MYSQL  
$db = new PDO("mysql:host=$mysql_host;dbname=$mysql_database", $mysql_user, $mysql_password);

$query = file_get_contents($script_path."sql.sql");

$stmt = $db->prepare($query);

if ($stmt->execute())
     echo "Success";
else 
     echo "Fail";
*/
?>
<?php

// Name of the file
$filename = $script_path.'/sql.sql';
// MySQL host
$mysql_host = 'localhost';
// MySQL username
$mysql_username = 'mssinfot_sms';
// MySQL password
$mysql_password = '123@qwe';
// Database name
$mysql_database = 'mssinfot_sms';

// Connect to MySQL server
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());

// Select database
mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

$checkQurtu=mysql_query("select id from query_table where status=1");
$check=mysql_fetch_array($checkQurtu);
if(is_array($check) && count($check)>0){
	// Temporary variable, used to store current query
	$templine = '';
	// Read in entire file
	$lines = file($filename);
	// Loop through each line
	foreach ($lines as $line)
	{
	// Skip it if it's a comment
	if (substr($line, 0, 2) == '--' || $line == '')
		continue;
	
	// Add this line to the current segment
	$templine .= $line;
	// If it has a semicolon at the end, it's the end of the query
	if (substr(trim($line), -1, 1) == ';')
	{
		// Perform the query
		mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
		// Reset temp variable to empty
		$templine = '';
	}
	}
	 echo "Tables imported successfully";
}
?>