note 61668 deleted from function.mysql-connect by nlopess
| From: | nlopess@php.net | Date: | Thu, 09 Feb 2006 00:05:03 +0000 |
| Subject: | note 61668 deleted from function.mysql-connect by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-103342@lists.php.net to get a copy of this message | ||
Note Submitter: frentzen at freemail dot nl
----
Just a very basic, solid mysql connection class:
<?php
class DBMysqlConnection
{ //v1.0 auto-connection on initiation
var $host, $dbname, $username, $handle, $error;
function DBMysqlConnection($IN_host, $IN_dbname, $IN_username, $IN_password)
{
$this->host = $IN_host;
$this->dbname = $IN_dbname;
$this->username = $IN_username;
$this->handle = @mysql_connect($IN_host, $IN_username, $IN_password);
if ($this->handle == false) $this->error = mysql_error();
else
{
if (@mysql_select_db($IN_dbname, $this->handle) == false) $this->error = mysql_error();
}
$this->CheckError();
}
function Disconnect()
{
if (@mysql_close($this->handle) == false) $this->error = mysql_error();
$this->CheckError();
}
function CheckError()
{
if (!empty($this->error)) die('<b>DBMysqlConnection fatal error:</b><br
/>'.$this->error);
}
}
$DBM = new
DBMysqlConnection('localhost','test','root','geheim');
//$DBM->handle
$DBM->Disconnect();
?>