PHP Database Connection

Submitted by:David Villa

Date added:24 September, 2012

Category:PHP

Connects to a database, and runs a query

Tags: database connection

Code Snippet:

<?php
class Database
{
var $sel;
var $con;
function __construct()
{
$this->connect();
}
function connect()
{
$this->con = mysql_connect("","","") or die(mysql_error());
$this->sel = mysql_select_db("") or die(mysql_error());
}
function close()
{
if(isset($this->connect))
{
mysql_close($this->connect);
unset($this->connect);
}
}
function query($res)
{
mysql_query($res) or die(mysql_error());
}
}

$database = new Database;
$database->connect();
?>
 
 

Comments