I didn't do this recently but in 2014, in a few WordPress projects that I need additional tables I used Laravel components.
In WordPress, if you want to create your own tables by using wpdb and mysql queries. But with the Laravel database classes I managed to do this much more elegantly.
A quick rundown how I do this:
(note: At the time, I used Laravel 4 components, I haven't tried with 5)
"require": {
"illuminate/database": "*",
"illuminate/container": "*",
"shuber/curl": "dev-master",
"sunra/php-simple-html-dom-parser": "v1.5.0"
},
I installed the necessary packages (first two) with composer in functions.php (or in a functionality plugin)
I used it for saving an index of magazine articles content, a Recorder class (not very SOLID approach, sorry)
<?php
namespace Dion\Volumes;
use Illuminate\Database\Capsule\Manager as Capsule;
class Recorder {
public static $table = 'volume_content';
public function __construct(Page $page){
$this->recordPage($page);
}
public static function createTables()
{
if( ! Capsule::schema()->hasTable(static::$table) ) {
Capsule::schema()->create(static::$table, function($table) {
$table->increments('id');
$table->string('volume');
$table->integer('month');
$table->integer('year');
$table->integer('page');
$table->longtext('page_content');
});
}
}
public function recordPage($page)
{
//check if exists
$exists = Capsule::table(static::$table)->where('volume',$page->volume)
->where('page',$page->page)->get();
if( empty( $exists ) ) {
$insert = Capsule::table(static::$table)->insert($page->toArray());
} else {
$update = Capsule::table(static::$table)->where('volume',$page->volume)
->where('page',$page->page)
->update($page->toArray());
}
}
}
and in the functions.php I added the Laravel database component and made it work like this.
global $wpdb;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => DB_HOST,
'database' => DB_NAME,
'username' => DB_USER,
'password' => DB_PASSWORD,
'prefix' => $wpdb->prefix,
'charset' => DB_CHARSET,
'collation' => 'utf8_unicode_ci',
));
$capsule->bootEloquent();
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
//this one creates table if not exists. Its better to run it in a WP action, like admin_init
$createVolumes = Dion\Volumes\Recorder::createTables();
Hope it helps, if you like this solution and have questions, I'll be happy to add more.