Jump to content

MySQL database


hmvrulz

Recommended Posts

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...

 

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





}

?>

Link to comment
https://forums.phpfreaks.com/topic/129058-mysql-database/
Share on other sites

Something I would recommend is making your own personal list of queries that will be run lots of times.  Create some constant strings that contain those queries.  Then, create a function for each query and pass mysql_query() that constant string.  Or, for something more complicated where you might need to use the results from one query in another, the function will help group that code together.  The constants are a good idea because it'll make your code easier to maintain if you use a given query in several places.

Link to comment
https://forums.phpfreaks.com/topic/129058-mysql-database/#findComment-674681
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.