Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * File Name: Database.php
- * Date: November 18, 2008
- * Author: Angelo Rodrigues
- * Description: Contains database connection, result
- * Management functions, input validation
- *
- * All functions return true if completed
- * successfully and false if an error
- * occurred
- *
- */
- class Database
- {
- /*
- * Edit the following variables
- */
- private $db_host = 'localhost'; // Database Host
- private $db_user = 'root'; // Username
- private $db_pass = 'root'; // Password
- private $db_name = 'blog'; // Database
- /*
- * End edit
- */
- private $con = false; // Checks to see if the connection is active
- private $result = array(); // Results that are returned from the query
- /*
- * Connects to the database, only one connection
- * allowed
- */
- public function connect()
- {
- if(!$this->con)
- {
- $myconn = @mysql_connect($this->db_host,$this->db_user,$this->db_pass);
- if($myconn)
- {
- $seldb = @mysql_select_db($this->db_name,$myconn);
- if($seldb)
- {
- $this->con = true;
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- else
- {
- return true;
- }
- }
- /*
- * Changes the new database, sets all current results
- * to null
- */
- public function setDatabase($name)
- {
- if($this->con)
- {
- if(@mysql_close())
- {
- $this->con = false;
- $this->results = null;
- $this->db_name = $name;
- $this->connect();
- }
- }
- }
- /*
- * Checks to see if the table exists when performing
- * queries
- */
- private function tableExists($table)
- {
- $tablesInDb = @mysql_query('SHOW TABLES FROM '.$this->db_name.' LIKE "'.$table.'"');
- if($tablesInDb)
- {
- if(mysql_num_rows($tablesInDb)==1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- /*
- * Selects information from the database.
- * Required: table (the name of the table)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement