PHP Database Tables Class: Store and retrieve class objects in database table

Recommend this page to a friend!
  Info   View files Example   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2021-06-07 (3 months ago) RSS 2.0 feedNot enough user ratingsTotal: 86 All time: 9,672 This week: 87Up
Version License PHP version Categories
vojjin 1.1Freeware7Databases, Utilities and Tools, Desig..., P..., P...
Description Author

This package can store and retrieve class objects in a database table.

It provides a base class that can perform the regular operations to insert, update, delete and select queries in a SQL database.

Application classes can extend the base class to store and retrieve their objects by defining some variables that determine how to map a class object into a given database table record.

Picture of Vojin Petrovic
  Performance   Level  
Name: Vojin Petrovic <contact>
Classes: 1 package by
Country: Serbia Serbia

Details
# PHP-Database-Tables-Class
---------------------
OOP Database class for PHP MySQL connection and insert, update, delete and select query for easier manipulating with tables

### CONFIG File

All database configurations are stored in seperate config.php file, which can be kept off document root.

### TABLE CLASSES

Whole idea is to create separate class for each table in the database and to manipulate data with ease.
e.g.

**class Article extends MySqlHelper {**

**public $id = 0;**

**public $title = "";**

**public function __construct(int $id = 0) {**

**$this->table = "articles";**

**$this->primaryKeyColumn = "id";**

**$this->columns = ["id" => MySqlHelper::type_int,"title" => MySqlHelper::type_str];**

**$this->loadRegular($id);**

**}**

**}**

### LOADING SINGLE ROW FROM A TABLE AND ASSIGN VALUES

e.g:

**$article = new Article(3);**

this will load row with id 3 in article class and convert all values appropriately. $article->id and $article->title in this case will be set

**$article->title = "New title";** //changing class value

**$article->update();** //updating article class values to table or

**$article->update(["title"]);** //updating just title value


### CUSTOM DATABASE CONNECTION AND QUERIES, IF NEEDED

Database class loads configuration file and establishes a MySQLi connect in constructor so just creating an instance of class connects you with database.


e.g:

**$db = new MySql();** // would connect to database

There are plenty of query types, reading whole tables, single rows, array of single column values, 
updating and deleting rows with or without where clause, counting row numbers, etc.

e.g:

**$db->insert("tablename",["column1","column2","column3"],[$value1,$value2,$value3]);** //inserting values in table

**$db->update("tablename",["column1","column2"],[$newvalue1,$newvalue2],$id);** // updating two columns to row with primar key value $id

**$db->updateWhere("tablename",["column1"],[$newvalue1],"id>?",[3]);** // updating column `column1` with value $newvalue1 to rows with `id` greater than 3

**$db->deleteWhere("tablename","id>?",[3]);** // deleting all rows with `id` greater than 3

Examples of Use:
---------------
index.php has a sample loading & editing values from tables, as well as reading POST and GET variables and assigning values to database.

  Files folder image Files  
File Role Description
Files folder imagevojjin (2 files, 3 directories)
Accessible without login Plain text file README.md Doc. Readme

  Files folder image Files  /  vojjin  
File Role Description
Files folder imagemysql (2 files)
Files folder imagetables (2 files)
Files folder imageutilities (2 files)
  Accessible without login Plain text file config.php Conf. DB configuration and spl loader
  Accessible without login Plain text file index.php Example index file with samples

  Files folder image Files  /  vojjin  /  mysql  
File Role Description
  Plain text file MySql.php Class MySql manage class
  Plain text file MySqlHelper.php Class helper for MySql

  Files folder image Files  /  vojjin  /  tables  
File Role Description
  Plain text file Article.php Class sample Article table class
  Plain text file Writer.php Class sample table class

  Files folder image Files  /  vojjin  /  utilities  
File Role Description
  Plain text file DateClass.php Class date time manipulation class
  Plain text file Utility.php Class simple utilities class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:86
This week:0
All time:9,672
This week:87Up
For more information send a message to info at phpclasses dot org.