Page 1 of 1

MySQL database

Posted: Sun Oct 19, 2008 3:25 am
by hmvrulz
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...

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);
                }
 
 
 
 
 
}
 
?>

Re: MySQL database

Posted: Sun Oct 19, 2008 3:46 am
by jaoudestudios
BTW...you could put your connect in the __construct! Therefore this will be 1 less method to call. And with this in mind you could put the disconnect method in the __destruct.

There are various ways you could do the INSERT, UPDATE, SELECT. Why dont you start it and we will help you.