Skip to content

Instantly share code, notes, and snippets.

@kuldipem
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuldipem/a2d8c24e7036e0f43f30 to your computer and use it in GitHub Desktop.
Save kuldipem/a2d8c24e7036e0f43f30 to your computer and use it in GitHub Desktop.
To install tables using php from .sql file.
<?php
if($_SERVER['REQUEST_METHOD']=="POST"){
if(empty($_POST["inputHost"]) ||
empty($_POST["inputDb"]) ||
empty($_POST["inputUsr"]) ||
empty($_POST["inputPwd"]) ||
die("<h1>All fields are required.</h1>");
}else{
// Name of the file
$filename = 'shoping.sql';
// MySQL host
$mysql_host = $_POST['inputHost'];
// MySQL username
$mysql_username = $_POST['inputUsr'];
// MySQL password
$mysql_password = $_POST['inputPwd'];
// Database name
$mysql_database = $_POST['inputDb'];
// 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());
// 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";
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="KULDIP PIPALIYA <kuldipem@gmail.com>">
<link rel="icon" href="favicon.ico">
<title>ShopingBox | Site Config </title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<!-- Custom styles for this template -->
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #eee;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
height: auto;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<form class="form-signin" action="" method="POST" >
<h2 class="form-signin-heading">Site Config</h2>
<label for="inputHost" class="sr-only">Host</label>
<input type="text" name="inputHost" id="inputHost" class="form-control" placeholder="Host name" required autofocus>
<label for="inputDb" class="sr-only">Database</label>
<input type="text" name="inputDb" id="inputDb" class="form-control" placeholder="DB name" required autofocus>
<label for="inputUsr" class="sr-only">Username</label>
<input type="text" name="inputUsr" id="inputUsr" class="form-control" placeholder="User name" required autofocus>
<label for="inputPwd" class="sr-only">Password</label>
<input type="password" name="inputPwd" id="inputPwd" class="form-control" placeholder="Password" required>
<br />
<br />
<button class="btn btn-lg btn-primary btn-block" type="submit">Install ShopingBox</button>
</form>
</div> <!-- /container -->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment