jd2007 Posted July 26, 2007 Share Posted July 26, 2007 <?php $db=mysql_connect("localhost", "root", [i]confidential[/i]) or die(mysql_error()); mysql_select_db("messenger"); ?> Quote Link to comment Share on other sites More sharing options...
yarnold Posted July 26, 2007 Share Posted July 26, 2007 Why do you need to? <?php class database { // Contains host private $ho; // Contains database name private $dn; // Contains database user private $du; // Contains user password private $up; public function __construct($ho, $dn, $du, $up) { // Sets the connection information $this->ho = $ho; $this->dn = $dn; $this->du = $du; $this->up = $up; } public function connect() { // Establishes a mysql connection and selects the database if(!$this->connection = mysql_connect($this->ho, $this->du, $this->up)) { // If we fail, tell the class that we have failed! throw new exception('MySQL Error :'.mysql_errno().' - Connection to mysql server could not be established -- '.mysql_error(), 1); } if(!mysql_select_db($this->dn,$this->connection)){ // If we fail to select the database, tell the class that we have done so! throw new exception('MySQL Error :'.mysql_errno().' - Database could not be selected -- '.mysql_error(), 1); } return true; } public function disconnect() { // Disconnects from the mysql server. return mysql_close($this->connection); } } // TO USE: $DBConnection = new database('localhost', 'messenger', 'yourusername', 'yourpassword'); $DBConnection->connect(); // Your db queries go here $DBConnection->disconnect(); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.