hmvrulz Posted October 19, 2008 Share Posted October 19, 2008 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 More sharing options...
Bendude14 Posted October 19, 2008 Share Posted October 19, 2008 what about something like this? <?php Select($value, $key, $table) { $sql = "SELECT * FROM $table WHERE $key='$value'"; $result = $this->query($sql); return $result; } ?> Then same principle for the other functions Link to comment https://forums.phpfreaks.com/topic/129058-mysql-database/#findComment-669119 Share on other sites More sharing options...
kenshintomoe225 Posted October 25, 2008 Share Posted October 25, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.