note 62322 added to function.mysql-connect

From: Date: Sat, 25 Feb 2006 03:12:15 +0000
Subject: note 62322 added to function.mysql-connect
Groups: php.notes 
Request: Send a blank email to php-notes+get-104397@lists.php.net to get a copy of this message
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(); ?> ---- Server IP: 216.194.113.175 Probable Submitter: 209.204.158.209 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62322 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62322&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62322&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62322&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62322&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62322&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62322&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62322&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62322&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104397) next »