PHP code example of avadim / manticore-query-builder-php
1. Go to this page and download the library: Download avadim/manticore-query-builder-php 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/ */
avadim / manticore-query-builder-php example snippets
use avadim\Manticore\QueryBuilder\Builder as ManticoreDb;
// Define config
$config = [
'defaultConnection' => 'default',
'connections' => [
// Default connection which will be used with environment variables
'default' => [
'host' => 'localhost',
'port' => 9306,
'username' => null,
'password' => null,
'timeout' => 5,
'prefix' => 'test_', // prefix that will replace the placeholder "?<table_name>"
'force_prefix' => false,
],
],
];
// Init query builder
ManticoreDb::init($config);
// Create table
ManticoreDb::create('?products', function (SchemaTable $table) {
$table->timestamp('created_at');
$table->string('manufacturer');
$table->text('title');
$table->json('info');
$table->float('price');
$table->multi('categories');
$table->bool('on_sale');
});
// Insert single row
$singleRow = [
'created_at' => time(),
'manufacturer' => 'Samsung',
'title' => 'Galaxy S23 Ultra',
'info' => ['color' => 'Red', 'storage' => 512],
'price' => 1199.00,
'categories' => [5, 7, 11],
'on_sale' => true,
];
$res = ManticoreDb::table('?products')->insert($singleRow);
// $res->result() => <id> of the new record
// Insert multiple rows
$multipleRows = [
[
'created_at' => time(),
'manufacturer' => '...',
'title' => '...',
'info' => [],
// ...
],
[
'created_at' => time(),
'manufacturer' => '...',
'title' => '...',
'info' => [],
// ...
],
];
$res = ManticoreDb::table('?products')->insert($multipleRows);
// $res->result() => array of <id> of new records
$rows = ManticoreDb::table('?products')->match('galaxy')->where('price', '>', 1100)->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.