Charas-Project

  • Home
  • Help
  • Search
  • Calendar
  • Login
  • Register
*
Please login or register.

Login with username, password and session length
 

News:

New forum theme up and running!



  • Charas-Project »
  • Off-Topic »
  • Archive »
  • Really Old Stuff »
  • PHP (Moderator: De KoFfieŠ) »
  • MySQL Code Install Script PHP Page
« previous next »
  • Print
Pages: [1]

Author Topic: MySQL Code Install Script PHP Page  (Read 5755 times)

Offline loftyD

  • Member
  • Associate
  • *
  • Posts: 150
MySQL Code Install Script PHP Page
« on: June 14, 2009, 08:33:20 AM »
If you want a simple mysql installing script than loading up PhpMyAdmin, I have made one for my piece of software, which I will post here soon!

1. GET MySQL CODE into .SQL FILE NAME "install.sql" (minus quotes)

Code: [Select]
-- Table structure for table `test_table`
--

CREATE TABLE IF NOT EXISTS `test_table` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `test` text COLLATE latin1_general_ci NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

2. COPY CODE INTO NEW PAGE

Code: [Select]


<html>
<head>
<title>Installation of YourApp</title>
</head>

<body>
<?php
//Script developed by loftyD. Please credit him!!!

$sub = $_POST['sub'] ;
$loc = $_POST['svr'] ;
$user = $_POST['mysql_user'] ;
$pass = $_POST['mysql_pass'] ;
$db = $_POST['mysql_db'] ;
if(isset(
$sub)) {

$con = mysql_connect($loc,$user,$pass) or die("Sorry invalid username or password.<br>");
$sel_db= mysql_select_db($db,$con) or die("Sorry database invalid or has not been created.<br>");
if(
$sel_db) {

$sqlFileToExecute = 'install.sql' ;
$newconnect = "<?php \$connect = mysql_connect('$loc', '$user', '$pass') ; $\db_selected = mysql_select_db($db, \$connect); ?>
" ;
strip_tags($newconnect) ;



        if ($conn !== false){
           // Load and explode the sql file
           $f = fopen($sqlFileToExecute,"r+");
           $sqlFile = fread($f,filesize($sqlFileToExecute));
           $sqlArray = explode(';',$sqlFile);
           
           //Process the sql file by statements
           foreach ($sqlArray as $stmt) {
              if (strlen($stmt)>3){
                 $result = mysql_query($stmt);
                 if (!$result){
                    $sqlErrorCode = mysql_errno();
                    $sqlErrorText = mysql_error();
                    $sqlStmt      = $stmt;
                    break;
                 }
              }
           }
        }

      $makefile = fopen('connect.php','w+') ;
  fwrite($makefile,$newconnect) ;
  echo "Database and SQL code successfully installed. Now delete this file immediately!" ;
  exit;
 



}


}

?>
<form action="<?PHP $_SERVER['PHP_SELF' ] ; ?>" method="POST">
MySQL Server (localhost should be fine): <input type="text" name="svr"><Br>
MySQL Username: <input type="text" name="mysql_user"><Br>
MySQL Password: <input type="password" name="mysql_pass"><Br>
MySQL Database (Please create before installing!) : <input type="text" name="mysql_db"><Br>
<input type="submit" name="sub" value="Submit">
</form>


</body>
</html>

3. PUT into WEBBROWSER and TEST!
Logged

Offline Osmose

  • So freakin' inactive
  • Royal
  • *
  • Posts: 3,041
Re: MySQL Code Install Script PHP Page
« Reply #1 on: June 30, 2009, 06:51:43 AM »
Actually all this will do is connect to an existing MySQL database and create a table. No offense, loftyD, but not too useful (I do like the parsing of a SQL file by lines).

If you have a server of your own and want to install MySQL, the downloads page at MySQL.com should have just what you need (Which is the Community Server). It comes in all sorts of easy to install flavors.

As for managing and configuring your database, two of the most popular ways are phpMyAdmin or, my personal preference, the MySQL GUI Tools. Most default MySQL installations have a username of root and a blank password, so you can use those to log in and add databases, tables, etc to your heart's content.
Logged
Hrm.

  • Print
Pages: [1]
« previous next »
  • Charas-Project »
  • Off-Topic »
  • Archive »
  • Really Old Stuff »
  • PHP (Moderator: De KoFfieŠ) »
  • MySQL Code Install Script PHP Page
 

  • SMF 2.0.10 | SMF © 2015, Simple Machines
  • XHTML
  • 2O11
  • RSS
  • WAP2
  • Simple Machines Forum