Simple PHP Install script for MySql Database

Discussion in 'PHP' started by bleucube, Dec 26, 2007.

  1. #1
    Does anyone have a generic script that asks the user Database name, Password, Server and than will import an sql file?

    Looking to build an installation for a mysql database.

    Thanks!
     
    bleucube, Dec 26, 2007 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    i can make for you $15

    50% advance

    Regards

    Alex
     
    kmap, Dec 26, 2007 IP
  3. bleucube

    bleucube Peon

    Messages:
    332
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No funds at the moment - sorry. Just looking for pointers. I found Micro DB Installer but you need the DB already created. Looking for something that does it all.
     
    bleucube, Dec 26, 2007 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #4
    why donot u use phpmyadmin

    Regards

    Alex
     
    kmap, Dec 26, 2007 IP
  5. bleucube

    bleucube Peon

    Messages:
    332
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is to provide an easy install for a php script with mysql backend.
     
    bleucube, Dec 26, 2007 IP
  6. x11joex11

    x11joex11 Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    class database
    {
    	var $host;
    	var $username;
    	var $password;
    	var $dbLink;
    	var $queryResult;
    	
    	//Constructor
    	function database($host,$username,$password)
    	{
    		$this->host=$host;
    		$this->username=$username;
    		$this->password=$password;
    	}
    	
    	//Utility Functions
    	function dbLoad($name)
    	{
    		$this->dbLink = mysql_connect($this->host,$this->username,$this->password);
    		if (!$this->dbLink) 
    		{
        		die('Could not connect: ' . mysql_error());
    		}
    		echo 'Connected successfully<br>';
    		
    		// make foo the current db
    		$db_selected = mysql_select_db($name, $this->dbLink);
    		if (!$db_selected) 
    		{
        		die ("Can't use $name : " . mysql_error());
    		}
    		else
    		{
    			echo "Found the Database $name";
    		}
    	}
    	
    	function dbQuery($query)
    	{
    		//$query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'",
        	//mysql_real_escape_string($firstname),
        	//mysql_real_escape_string($lastname));
    
    		// Perform Query
    		$result = mysql_query($query);
    
    		// Check result
    		// This shows the actual query sent to MySQL, and the error. Useful for debugging.
    		if (!$result) 
    		{
        		$message  = '<BR>Invalid query: ' . mysql_error() . "\n<BR>";
        		$message .= 'Whole query: ' . $query;
        		if(preg_match('/Duplicate entry/si',$message,$tempMatch)<>1)
        		{
        			die($message);
        		}
        		else
        		{
        			echo "<br>Not Halting Since Duplicate: ".$message;
        		}
    		}
    		return $result;
    	}
    }//END OF CLASS****************************************************************
    
    PHP:
    Here is a class I made for accessing a database, I always include it in my projects.

    Here is an example of how to use it

    function createDataTables(&$database)
    {
    	$database->dbQuery("CREATE TABLE wiki_entry_table(id INT NOT NULL AUTO_INCREMENT,entity_name TEXT(30),address TEXT,first_paragraph TEXT,PRIMARY KEY (id),UNIQUE INDEX entity_name( entity_name( 30 ) ))");
    	echo '<BR>Table wiki_entry_table Created';
    	$database->dbQuery("CREATE TABLE data_table(id INT,attribute TEXT,value TEXT)");
    	echo '<BR>Table data_table Created';
    }
    
    PHP:
    This is a createDataTables function I made, that is activated when $_GET['install']=1, you could just do something like this
     
    x11joex11, Dec 26, 2007 IP