Welcome ,
  1. Home
  2. Database Tables

PageCarton Documentation



Interested in coding widgets, classes, or methods? Check out the Code section!

Database Tables

Database Tables are similar to Widgets, only that they don’t output anything. They also extends PageCarton_Table core PageCarton class. They are meant to guide the PageCarton core as to how to store data on the server.


Image

When building a plugin, a lot of times we want to store data for various purposes. Database is the heart of building a dynamic application where data is being manipulated based on user action. Data could be stored, retrieved and manipulated through a central storage system powered by PageCarton Database Tables.

Creating a Database Table

The process of creating Database Tables is similar albeit a lot easier than widgets.  

PageCarton Admin Panel > Plugins > My Plugins > "New DB Table"

Unlike the widget, customizing the Database Table after creation is not required. After entering the class name and database fields, and data types, the Class file is created automatically and the Database tables can be used immediately. Database Tables are mostly used in Widgets through API calls.

Database Table APIs

In other to demonstrate the usage of the Database Table APIs, we will be using a hypothetical table with class name 'My_First_Widget_Table'. It stores user comments using field names 'first_name', 'email_address' and 'comment'. All the field names have 'TEXT' datatypes. Usage of some of the APIs are illustrated below:

Instantiating the Database Table

$table = new My_First_Widget_Table();

Writing to Database

$record1 = array(  'first_name' =>  'John', 'email_address' =>  'john@example.com',  'comment' =>  'This site is cool' );
$table->insert( $record1 );
$record2 = array(  'first_name' =>  'Ade', 'email_address' =>  'ade@example.com',  'comment' =>  'Nice and smooth' );
$table->insert( $record2 );

Retrieving Data from Table

//	Seek rows for comments by "John"
$where = array(  'first_name' =>  'John' );	
$rows = $table->select( null, $where );
var_dump( $rows );
//	outputs array( 0 => array(  'first_name' =>  'John', 'email_address' =>  'john@example.com',  'comment' =>  'This site is cool' ) );

Update Records

$table->update( $newRecordValues, $where );

Delete Records

$table->delete( $where );

 

 

 

← Previous "Changing Number of Posts to Display on a Widget""Setting up PageCarton via Docker" Next →


 

Similar Documentation Article

 

Changing Number of Posts to Display on a Widget Photo

Changing Number of Posts to Display on a Widget

Another interesting customization feature just came in the latest PageCarton. Users of PageCarton can now change the number of post shown in embedded widget from the admin panel. For example, be...

Documentation Article
 

 

Installing PageCarton via Composer Photo

Installing PageCarton via Composer

If you have Composer installed on your computer, you can easily get PageCarton up by running the following commands on your command line.  # download PageCarton via composer composer c...

article
 

 

Setting up PageCarton via Docker Photo

Setting up PageCarton via Docker

PageCarton now has a few files in its GitHub repository that helps to set it up on Docker easily. If you are familiar with Docker or a newbie, you should be able to get started with PageCarton...

article
 

 

Steps in Creating a PageCarton Website Offline Photo

Steps in Creating a PageCarton Website Offline

Creating a website has now been made easy with the use of Pagecarton, it's not necessary to know much about coding. If you have your contents ready, and the style of how your website wants to...

article
 

 

Steps in Creating a PageCarton Theme Photo

Steps in Creating a PageCarton Theme

Creating a PageCarton theme isn't actually a difficult task, but just that it might involve a long process and a little bit of how programming codes work. The main purpose of having a PageCarto...

article
 

 

HTML Syntax & API for Embedding Widgets Photo

HTML Syntax & API for Embedding Widgets

In an update to PageCarton that was available from August 2020, we added a new way to create and customize PageCarton Themes. In addition to existing ways of creating ...

article