PHP -> MySQL Connection script

Discussion in 'PHP' started by regbeta, Jun 14, 2009.

  1. #1
    Hello! =D

    Create a file, and rename it to: configuration.php
    Insert this and edit:
    <?php
    class connection {
    	private $config = array("host" => "localhost", "user" => "root", "pass" => "WRITE YOUR PASS HERE", "link" => NULL, "db" => "WRITE YOUR DB NAME HERE");
    
    	function connect(){
            $this->config["link"] = mysql_connect($this->config["host"],$this->config["user"],$this->config["pass"]) or
            exit (mysql_error());
            mysql_select_db($this->config["db"]) or exit (mysql_error());
        }
    
    	function disconnect(){
            mysql_close($this->config["link"]) or exit (mysql_error());
        }
    	
    	function query($querystring) {
    		$this->num_queries++;
    		$this->queryid = mysql_query($querystring,$this->config["link"]);
    		$this->row   = 0;
    		if (!$this->queryid) {
    			die("ERROR: ".$querystring);
    		}
    		return $this->queryid;
    	}
    		
    	function fetch_array($queryid=-1,$querystring="") {
    
    		if ( isset($this->queryid) ) {
    			$this->record = mysql_fetch_array($this->queryid);
    		} else {
    			if ( !empty($querystring) ) {
    				die("Invalid query (".$this->queryid.") on: $querystring");
    			} else {
    				die("Invalid query ID ".$this->queryid."");
    			}
    		}
    		return $this->record;
    	}
    }
    ?>
    PHP:
    Before, create a file called something and insert:

    <?php include ("configuration.php"); ?>
    <?php
    
     $userid = $_GET['userid'];
     
    $connection = new connection();
    $connection->connect(); 
    $showdata = mysql_query( "SELECT * FROM user WHERE id='$userid'" );
     if($showdata) {
    	while ($list = mysql_fetch_array($showdata)){
    	echo "<table width=100% border=0 align=center>
     <tr>
      <td colspan=4 align=center><strong>$list[name] $list[lastname] INFO</strong></td>
     </tr>
     <tr><td class=add>Name</td><td>$list[name]</td></tr>
     <tr><td class=add>Lastname</td><td>$list[lastname]</td></tr>
     </table>";
    	}
    }
    else if(!$showdata)
    	$connection->disconnect();
    echo "Not found!";
    
    ?>
    
    PHP:
    Now go to localhost/YOURFILENAME.php?userid=HERE A ID
     
    regbeta, Jun 14, 2009 IP
  2. regbeta

    regbeta Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Any issue? Reply this =)
     
    regbeta, Jun 14, 2009 IP
  3. uselessguy

    uselessguy Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what you exactly want to know?
     
    uselessguy, Jun 14, 2009 IP
  4. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #4
    I think they were demonstrating this?
     
    tguillea, Jun 14, 2009 IP
  5. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #5
    and? what's the question?
     
    crivion, Jun 15, 2009 IP
  6. regbeta

    regbeta Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It is a easy connection script to other peoples...
     
    regbeta, Jun 15, 2009 IP
  7. regbeta

    regbeta Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes! I an demonstrating that script
     
    regbeta, Jun 15, 2009 IP
  8. UnknownOne

    UnknownOne Banned

    Messages:
    466
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8


    You mean remote connection?
     
    UnknownOne, Jun 16, 2009 IP