note 108870 deleted from function.mysql-connect by thiago

From: Date: Thu, 31 May 2012 15:27:26 +0000
Subject: note 108870 deleted from function.mysql-connect by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-188325@lists.php.net to get a copy of this message
Note Submitter: http://codingquery.com ---- php and mysql are like those sweet couples who never be without each other or you can say made for each other. when a php fresher writes his/her first line of code in php from that day he/she knows the truth. From technical point of view they are very much compatible with each other and the Phpmyadmin has done the finishing touch perfectly. Though we can connect php with other databases or use mysql db as back-end with other platforms but in 99% cases php is used with mysql. Not as because both are free , because of the inbuilt functions in php for accessing mysql data. mysql_connect([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string$password = ini_get("mysql.default_password") [, bool $new_link = false [, int $client_flags = 0 ]]]]] ); $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); class Database { // Connection parameters var $host = ""; var $user = ""; var $password = ""; var $database = ""; var $persistent = false; // Database connection handle var $conn = NULL; // Query result var $result = false; function Database() { $config = new Config(); $this->host = $config->host; $this->user = $config->user; $this->password = $config->password; $this->database = $config->database; } function open() { // Choose the appropriate connect function if ($this->persistent) { $func = 'mysql_pconnect'; } else { $func = 'mysql_connect'; } // Connect to the MySQL server $this->conn = $func($this->host, $this->user, $this->password); if (!$this->conn) { header("Location: error.html"); //echo mysql_error(); exit; return false; } For full source code please read the full article http://www.codingquery.com/php-mysql-connection-class-source-code I am very helpfull from thjis article

« previous php.notes (#188325) next »