Mac
New Member
- Feb 9, 2011
- 111
- 2
class.MySQLprogram.php :
yourothersfilename.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!
?>