Show DevBest [PHP OOP] Mac's Complete MySQL program

Status
Not open for further replies.

Mac

New Member
Feb 9, 2011
111
2
class.MySQLprogram.php :
PHP:
<?php
/*------------------------------------------*\
| Complete MySQL program programmed by Mac   |
\*------------------------------------------*/
class MySQLPROGRAM {
	public $mysqlI = array(); # Private informations , you don't need to put anything in the array.
	public function __construct( $a, $b, $c, $d, $e ) {
		if( isset( $a, $b, $c, $d, $e ) ):
			if($a !== "MySQL"):
				die("This program can use only MySQL");
			else:
				$this->mysqlI["host"] = $b;
				$this->mysqlI["user"] = $c;
				$this->mysqlI["pass"] = $d;
				$this->mysqlI["dbn"] = $e;
				mysql_connect($this->mysqlI["host"], $this->mysqlI["user"], $this->mysqlI["user"]) or die("<p>".mysql_error()."</p>");
				mysql_select_db($this->mysqlI["dbn"]) or die("<p>".mysql_error()."</p>";
			endif;
		else:
			die("One of primary keys for construct function is not set!");
		endif;
	}
	/* If you are a coder you can add more functions in this class like num_rows , fetch_array but i don't really like it. */
	public function change($a, $b) {
		if(isset($a, $b)):
			if($a !== "host" or $a !== "user" or $a !== "pass" or $a !== "dbname"):
				echo "This key can't be changed!";
			else:
				if($a == "host"):
					$this->mysqlI["host"] = $b;
                                        mysql_connect($b, $this->mysqlI["user"], $this->mysqlI["pass"]);
				endif;
				if($a == "user"):
					$this->mysqlI["user"] = $b;
                                        mysql_connect($this->mysqlI["host"], $b, $this->mysqlI["pass"]);
				endif;
				if($a == "pass"):
					$this->mysqlI["pass"] = $b;
                                        mysql_connect($this->mysqlI["host"], $this->mysqlI["user"], $b);
				endif;
				if($a == "dbname"):
					$this->mysqlI["dbn"] = $b;
                                        mysql_select_db($b);
				endif; 
			endif;
		else:
			echo "Please enter the key you wanna change and then the value!";
		endif;
	}
}
?>

yourothersfilename.php :
PHP:
<?php
$PROG = new MySQLPROGRAM("MySQL", "MYSQL HOST", "root", "MYSQL PASSWORD", "MYSQL DATABASE NAME");
echo "<p>You are visiting ".$PROG->mysqlI["host"]."</p>";
echo "<p>Your MySQL username is ".$PROG->mysqlI["user"]."</p>";
echo "<p>Your MySQL password is ".$PROG->mysqlI["pass"]."</p>";
echo "<p>Your MySQL database name is ".$PROG->mysqlI["dbn"]."</p>";
	
# Use $PROG->change("what", "towhat") to change variables.
# "what" should be host , user , pass or dbname or it won't work!
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
I don't see the point in the $a variable?

PHP:
mysql_select_db($this->mysqlI["dbn"]) or die("<p>".mysql_error()."</p>";

Where is the bracket to end the statement after
PHP:
</p>";

Shouldn't it be:
PHP:
</p>" );
?
 

Jo$h

Posting Freak
Jul 7, 2010
1,030
79
This seems pretty pointless to me as I just use the require function that has all of my MySQL details in it.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Another thing that bothers me is, why would you want to display your MySQL details publicly?
 
Status
Not open for further replies.

Users who are viewing this thread

Top