PHP code example of techmobi / multidb
1. Go to this page and download the library: Download techmobi/multidb 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/ */
techmobi / multidb example snippets
...
'original' => env('DB_CONNECTION', 'mysql'), // <-- ADD THIS LINE
'connections' => [
...
//ADD THIS ARRAY
'multidb' => [
'driver' => 'mysql',
'engine' => 'InnoDB',
'host' => env('MULTIDB_HOST', 'localhost'),
'port' => env('MULTIDB_PORT', 3306),
'database' => env('MULTIDB_DATABASE', 'database'),
'username' => env('MULTIDB_USERNAME', ''),
'password' => env('MULTIDB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'varcharmax' => 191,
],
...
]
...
class Product extends Model
{
use \Techmobi\Multidb\Traits\UsesMultiConnection;
...
}
class Product extends Model
{
use \Techmobi\Multidb\Traits\UsesMainConnection;
...
}
class Product extends Model
{
use \Techmobi\Multidb\Traits\UsesMultiConnection;
...
public $attachMany = [
'images' => [
'Techmobi\Multidb\Models\File',
'softDelete' => true,
],
];
...
}
class MediaLibrary
{
use \October\Rain\Support\Traits\Singleton;
use \Techmobi\Multidb\Traits\UsesMultiConnection;
...
protected function init()
{
$this->getDomainData();
if (!empty($this->getDatabaseName())) {
$this->storageFolder = "/{$this->getDatabaseName()}/media";
$this->storagePath = "/storage/app/{$this->getDatabaseName()}/media";
} else {
$this->storageFolder = self::validatePath(Config::get('cms.storage.media.folder', 'media'), true);
$this->storagePath = rtrim(Config::get('cms.storage.media.path', '/storage/app/media'), '/');
}
$this->ignoreNames = Config::get('cms.storage.media.ignore', FileDefinitions::get('ignoreFiles'));
$this->ignorePatterns = Config::get('cms.storage.media.ignorePatterns', ['^\..*']);
$this->storageFolderNameLength = strlen($this->storageFolder);
}
...
}
Event::fire('techmobi.schema.set', 'my_awesome_schema');