Aanmelden
Inloggen
Wachtwoord vergeten
Online: 7
 
     Top 5:
CriminalsForum
wmpoint
Hacktech
Omroep Voor Jou
World-war
 > Je site hier plaatsen?

Uw banner hier?
  Forum

  Alle Actieve topics
Topic open! [15:19] Je websit...
Topic open! [17:52] Klikkaa S...
Topic open! [16:26] procent b...
Topic open! [16:19] WoW Forum
Topic open! [16:18] Gezocht
Topic open! [17:38] Banner / ...
Topic open! [17:36] Advertise...
Topic open! [01:03] {Vrijwill...
Topic open! [00:58] World-War
Topic open! [14:48] Webblog s...
Meer ...

AddThis Feed Button

  Werk
Vacature Wearekillers.tk
Vacature Start from scratch!
Vacature q-star.nl
Vacature Digitaal leren
Vacature Voetbal Site

  Marktplaats
Topic open! [01:11] Advertent...
Topic open! [13:08] Cmshero -...
Topic open! [22:05] Verkoop u...
Topic open! [17:46] Maffia sc...
Topic gesloten! [22:45] Verkoop p...

  Actieve kennis topics
Topic open! [18:41] Leden tel...
Topic open! [21:43] PHP bug

AddThis Feed Button
  Opties
Script toevoegen | Categorie:

  SQL installer
Postdatum: 2008-10-15 18:26:46 Directe link Naar boven
Telenet7 - Premium schrijver PB
Offline

Kwaliteitsscore: +53
WS V3 - The future
Uitleg
Installeert voor een applicatie de benodigende MySQL tables.
-De querys die worden uitgevoerd staan gedefineerd in de constante SQL_FILE.
-DB_FILE is de de constante die staat voor het doel waarin de databaseconnection wordt opgeslagen. Je kan er paths in in geven om ze in andere mappen te laten schrijven.

Dit script kan bevoorbeeld handig zijn om een applicatie te laten installeren door een leek, zodat die niet moet rommelen in de broncode.
Have fun with it!
Script
Php code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
//////////////////////////////////////////////////////////////////
//Scriptname: \'databaseinstaller 1.0\'                            ///
//Written by: telenet7 
            
//////////////////////////////////////////////////////////////////
 
//////////////////////////////////////////
////    Configuration:                   ///
//////////////////////////////////////////
define('SQL_FILE\',\'sql.sql\');    //file where CREATE TABLE querys are written
define(\'DB_FILE\',\'db.php\');     //new file where the database connection functions will be written to
 
//////////////////////////////////////////
////    do not edit beneath this line! ///
//////////////////////////////////////////
if(!IsSet($_GET[\'send\']))
{
    //print form
    ?>
    <style>
label {
      display: block;
}
</style>
 
<title>Webscripters.be</title>
 
<h1>Install database</h1>
<p>Welcome to the installation of your MySQL database. Please follow the next steps for a safe and easy configuration.</p>
 
<form method=\"post\" action=\"?send\">
      <label for=\"user\">Username:</label> <input name=\"user\" id=\"user\" type=\"text\" value=\"\">
         <label for=\"password\">Password:</label> <input name=\"password\" id=\"password\" type=\"text\" value=\"\">    
      <label for=\"host\">Host:</label> <input name=\"host\" id=\"host\" type=\"text\" value=\"localhost\">
      <label for=\"database\">Databasename:</label> <input name=\"database\" id=\"database\" type=\"text\" value=\"Name\">
      <br>
      <label for=\"permanent\" style=\"display: inline;\">Permanent databaseconnection:</label> <input type=\"checkbox\" name=\"permanent\" id=\"permanent\" value=\"true\">  
      <br><br>
      <input type=\"submit\" value=\"Install\">
</form>
   <?php
}
else
{
    @mysql_connect($_POST[\'host\'],$_POST[\'user\'], $_POST[\'password\']) or ($ErrorCode = mysql_errno());
    
    if(IsSet($ErrorCode))//connection failed
    {
        echo \'<h1>Database connection error</h1>\';
        if($ErrorCode == 1045)
            echo \'<p>Wrong username / password. Please try again.</p>\';
        elseif($ErrorCode == 2005)
            echo \'<p>Wrong host selected. Please try again.</p>\';
        else
            echo \'<p>Unknown error. Try again, and if this error continues, contact the developer of this software.</p>\';
            
        echo \'<p><a href=\"\'. $_SERVER[\'PHP_SELF\'] .\'\">Back</a></p>\';
    }
    else
    {
        mysql_query(\'CREATE DATABASE IF NOT EXISTS \'.$_POST[\'database\']);
        mysql_select_db($_POST[\'database\']);
        
        @mysql_query(\"START TRANSACTION;\");//open transaction (see mysql.com)
        
        $querys = @file_get_contents(SQL_FILE);
 
        if(empty($querys))
            die (\'<p>SQL file is empty or doesn\\\'t exists. Try again, and when this problem continues, contact the developer of this software.</p>\');
        
        @mysql_query($querys) OR ($errors[] = mysql_error());
        
        if(IsSet($errors))
        {
            echo \'<h1>Corrupted SQL file</h1>\';
            echo \'<p>The used SQL file for inserting al the application databasetables, seems to containts wrong SQL lines. Your database couldn\\\'t be installed correctly. If this problem continues, contact the developer of this software.<br>Next errorlines where returned by MySQL:</p>\';
            echo \'<ul>\';
            foreach($errors AS $error)
                echo \'<li>\'. $error .\'</li>\';
            echo \'</ul>\';
                
            @mysql_query(\'ROLLBACK;\');//deny querys
        }
        else
        {
            @mysql_query(\'COMMIT;\');//complete querys
            
            if(IsSet($_POST[\'permanent\']))
                $functie = \'mysql_pconnect\';
            else
                $functie = \'mysql_connect\';
            
            $DbFile = \"<?php\". $functie . \"(\'\". strtolower($_POST[\'host\']) .\"\',\'\". $_POST[\'user\'] .\"\',\'\". $_POST[\'password\'] .\"\') or die(mysql_error()); \\nmysql_select_db(\'\". strtolower($_POST[\'database\']) .\"\') or die(mysql_error());?>\";
        
            $fp = fopen(DB_FILE,\"w\");//make new file, deleted old file when exists
            fwrite($fp,$DbFile);
            fclose($fp);
            
            echo \'<h1>Database succesfully installed</h1>\';
            echo \'<p>The database is completly installed and configured. You can now use your PHP-application. Reload <a href=\"\'. $_SERVER[\'PHP_SELF\'] .\'?\'. $_SERVER[\'QUERY_STRING\'] .\'\">this page</a> to begin.</p>\';
        }
    }
}
?>

BewerkReacties (0) - Reageer

  Rating
Er hebben in totaal 0 leden gestemd.

  Leden Online
7 Bezoekers online, waarvan 0 leden ingelogd.
© WebScripters 2005-2009 || GameColl Project