MySQL database
Posted: Sun Oct 19, 2008 3:25 am
I have created a class to handle my mysql stuff...
Can some one Tell me how i can include methods for
INSERTING , UPDATE, SELET, DELETE in to this
If am taking keys..values as an array...
Can some one Tell me how i can include methods for
INSERTING , UPDATE, SELET, DELETE in to this
If am taking keys..values as an array...
Code: Select all
<?php
class dbHandler
{
// Defining CONNECTION Parameters
const HOST = 'localhost'; // SERVER
const USERNAME = 'abc'; // Username
const PASSWORD = '123'; // Password
const DATABASE = 'db'; // Database
// Method to Connect to the database and select it.
function connect()
{
$this->conn = mysql_connect(HOST, USERNAME, PASSWORD) or die("Connection to the Database Failed!!!");
mysql_select_db(DATABASE);
}
// Method to Process the general Queries.
function query($query)
{
$result = mysql_query($query, $this->conn) or die("Database Query Failed !!! <br/> $query <br/>" .
mysql_error());
return $result;
}
// Method to Fetch data from the Database in the form of Array Assoc
function fetchArray($query)
{
$result = $this->query($query);
$result = mysql_fetch_assoc($result);
return $result;
}
// Method to fetch No of Rows
function numRows($query)
{
$result = $this->query($query);
$result = mysql_num_rows($result);
return $result;
}
// Method to Disconenct the Opened Conenction
function disconnect()
{
mysql_close($this->conn);
}
}
?>