note 62322 deleted from function.mysql-connect by bjori

From: Date: Sat, 15 Apr 2006 18:42:10 +0000
Subject: note 62322 deleted from function.mysql-connect by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108198@lists.php.net to get a copy of this message
Note Submitter: davidsims at pantherdev dot com ---- Using OOP with MySQL is a good idea. By using the classed based method you can avoid continuely inputting/outputting MySQL db info. For example: <?php class DB { var $ident; var $sql = array('host'=>'localhost','user'=>'user','pass'=>'pass','db'=>'db'); function connect () { // Connect to MySQL $this->ident = mysql_connect($this->sql['host'], $this->sql['user'], $this->sql['pass']); // Select assigned DB if (!mysql_select_db($this->sql['db'])) { die("Could not connect to DB"); } } function disconnect () { // Close the connection if (!mysql_close($this->ident)) { die("Could not close DB"); } } } $DB = new DB(); // Connect with info $DB->connect(); // Close connection $DB->disconnect(); ?>

« previous php.notes (#108198) next »