Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- THIS CLASS CONTAINS DATABASE RELATED FUNCTIONS
- FUNCTIONS USED IN THIS CLASS:
- db_connect() Connects to the database
- db_select() Selects the database
- db_query() Queries the database
- db_error() Returns the database error
- db_close() Closes the connection to the database
- count_rows() Returns the amount of rows in a result
- */
- class database
- {
- private $db_host = 'localhost';
- private $db_user = 'root';
- private $db_pass = '';
- private $db_name = 'escortz_db';
- //
- // CONNECTS TO THE SERVER AND SELECTS THE DATABASE
- //
- function database()
- {
- $this->database_connection = $this->db_connect($this->db_host, $this->db_user, $this->db_pass) or die($this->db_error());
- $this->db_select($this->db_name) or die($this->db_error());
- // This will prevent some problems on MySQL5+ servers
- mysql_query("SET sql_mode='MYSQL40'", $this->database_connection);
- }
- // END init()
- //
- // CONNECT TO THE DATABASE
- //
- function db_connect($db_host, $db_user, $db_pass)
- {
- return mysql_connect($this->db_host, $this->db_user, $this->db_pass, TRUE);
- }
- // END db_connect()
- //
- // THIS METHOD SELECTS A DATABASE
- //
- function db_select($db_name)
- {
- return mysql_select_db($this->db_name, $this->database_connection);
- }
- // END db_select()
- //
- // THIS METHOD QUERIES A DATABASE
- //
- function db_query($query)
- {
- $result = mysql_query($query, $this->database_connection);
- return $result;
- }
- // END db_query()
- //
- // THIS METHOD RETURNS THE DATABASE ERROR
- //
- function db_error()
- {
- return mysql_error($this->database_connection);
- }
- // END db_error()
- //
- // THIS METHOD CLOSES THE CONNECTION TO THE DATABASE SERVER
- //
- function db_close()
- {
- return mysql_close($this->database_connection);
- }
- // END db_close()
- //
- // THIS METHOD RETURNS THE NUMBER OF ROWS IN A RESULT
- //
- function count_rows($result)
- {
- if( !is_resource($result) ) return FALSE;
- return mysql_num_rows($result);
- }
- // END database_row_count()
- //
- // FETCHES A ROW AS A NUMERIC ARRAY
- //
- function db_fetch_array($database_result)
- {
- if( !is_resource($database_result) ) return FALSE;
- return mysql_fetch_array($database_result);
- }
- // END database_fetch_array()
- }
- ?>
Add Comment
Please, Sign In to add comment