Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** Class table **/
- include_once("db.php");
- class DbTable{
- private $table_name;
- private $query;
- private $db;
- function __construct($table_name){
- $this->db = new DataBase();
- $this->table_name = $table_name;
- }
- /**
- Prepare and execute query
- @param query SQL
- @param query_array array
- **/
- function _query($query, $query_array = ""){
- try{
- $this->db->query("SET NAMES UTF8");
- if ($query_array != ""){
- $rqq = $this->db->prepare($query);
- $rqq->execute(array($query_array));
- }
- else{
- $this->db->query($query);
- }
- return true;
- }
- catch(Exception $e){
- die("Error : " . $e->getMessage());
- return false;
- }
- }
- /**
- Show spécific item
- @param item_name string
- **/
- function show_item($item_name){
- $rqq = "SELECT ".$item_name." FROM ".$this->table_name;
- $found_item = $this->_query($rqq);
- return $found_item;
- }
- /**
- Add item
- @param item_attr string
- @param item_val string
- **/
- function add_item($item_attr="", $item_val=""){
- $rqq = "INSERT INTO " . $this->table_name . "(" . $item_attr . ") VALUES (".$item_val.")";
- try{
- $this->_query();
- }
- catch(Excepetion $e){
- die('Error : '.$e->getMessage());
- return false;
- }
- }
- function update_item(){
- // WIP
- }
- function remove_item(){
- // WIP
- }
- function list_item(){
- $rqq = "SELECT * FROM ".$this->table_name;
- $list_item = $this->query($rqq);
- return $list_item;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement