PHP code example of calderawp / caldera-db

1. Go to this page and download the library: Download calderawp/caldera-db library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

calderawp / caldera-db example snippets


use calderawp\DB\Factory;
use calderawp\interop\Attribute;

//id column
$attributeData = [
    'name' => 'id',
    'sqlDescriptor' => 'int(11) unsigned NOT NULL AUTO_INCREMENT',
    'format' => '%d',
];

//name column
$attribute2Data = [
    'name' => 'name',
    'sqlDescriptor' => 'varchar(256) NOT NULL',
    'format' => '%s',
];

//name of table
$tableName = 'cf_whatever';
//name of primary key(s)
$primaryKey = 'id';
//name of index(es)
$indexes = ['name'];

//Create factory
$factory = new Factory();
//Create Table schema
$attributes = [$attributeData, $attribute2Data];
$tableSchema = $factory->tableSchema($attributes, $tableName, $primaryKey, $indexes);
//Create table using WordPress' wpdb
$table = $factory->wordPressDatabaseTable($tableSchema,$wpdb);