Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * @DATABASE
- * ~~~~~~~~~~~~
- * @FILE DESCRIPTION: Handles all database related processes
- * @LAST MODIFIED: April 4, 2012
- */
- class database
- {
- protected $dbc;
- function __construct($db_host, $db_name, $db_user, $db_password)
- {
- try
- {
- $this->dbc = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_password);
- }
- catch(PDOException $e)
- {
- echo '<b>An error occured while trying to create a database connection: </b>'. $e->getMessage();
- }
- }
- /*
- * @METHOD setPDOAttribute
- * @DESC Sets a PDO attribute for our dbc object
- */
- public function setAttribute($first_param, $second_param)
- {
- try
- {
- $this->dbc->setAttribute($first_param, $second_param);
- }
- catch(PDOException $e)
- {
- echo 'PDOException Error: '. $e->getMessage();
- }
- }
- /*
- * @METHOD processInsertQuery
- * @DESC use for all queries BESIDES a select query
- */
- public function processQuery($query, array $binds, array $assign)
- {
- $query_handle = $this->dbc->prepare($query);
- $i = 0;
- $value = array();
- foreach($binds as $bind)
- {
- $query_handle->bindParam($bind, $value[$i]);
- $value[$i] = $assign[$i];
- $i++;
- }
- $query_handle->execute();
- }
- public function queryFetch($query)
- {
- //FETCH A QUERY
- }
- public function insert($query)
- {
- $this->dbc->exec($query);
- }
- public function close_connection()
- {
- if($this->dbc != null)
- {
- $this->dbc = null;
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment