WHMCS database management intro

February 24, 2017

Unfortunately WHMCS documentation does not give enough information about database management.

On WHMCS 7 (actually from previous versions already) they implemented they take advantage of Laravel framework’s database component.

You can find some info on the WHMCS documentation that is probably useful if you don't need example to understand what to do. I think in this case is mandatory to include a link to Laravel query builder, for reference on how to create your queries.

First of all, to use it it's necessary to initialize Capsule, including this row of code at the beginning of your php file

use Illuminate\Database\Capsule\Manager as Capsule;

Now we can make queries, for example if we want to get all records from a table we can use:

$users = Capsule::table('users')->get();

Or if you want to retrieve a single column from a row:

$name = Capsule::table('users')->where('name', 'John')->pluck('name');

Update values in your database

Capsule::table('users')->where('id', 1)->update(array('votes' => 1));

Or insert a new row in the database

Capsule::table('users')->insert( array('email' => 'john@example.com', 'votes' => 0));

One comment on “WHMCS database management intro”

Leave a Reply to WHMCS Database Select and loop through results – WHMCS Tricks Cancel reply

Your email address will not be published. Required fields are marked *

usersspell-checksmile