Interface: IShardManager

Interface for managing connections to the DB shards.

Known implementations

Authors

Oleg Schildt

Package

Source code

 

Methods
public

The method provides the DBWorker object for working with the shard.

public

The method provides the DBWorker object for working with the shard, that is chosen randomly for load balancing reason.

public

Registers a new shard.


Method: IShardManager::dbshard()

public function dbshard(string $shard_name): ?\SmartFactory\DatabaseWorkers\DBWorker;

The method provides the DBWorker object for working with the shard.

Details

If the parameters are omitted, the system takes the parameters from the configuration settings and reuses the single instance of the DBWorker for all requests. If the user passes the parameters explicitly, a new instance of the DBWorker is created upon each new request.

Currently supported: MySQL und MS SQL.

Parameters

Name Pass type Value type Default value Description
$shard_name by value string

The name of the shard.

Returns

?\SmartFactory\DatabaseWorkers\DBWorker

returns DBWorker object or null if the object could not be created.

Throws

\Exception

It might throw an exception in the case of any errors.

Authors

Oleg Schildt

Source code


Method: IShardManager::randomDBShard()

public function randomDBShard(string $load_balancing_group): ?\SmartFactory\DatabaseWorkers\DBWorker;

The method provides the DBWorker object for working with the shard, that is chosen randomly for load balancing reason.

Parameters

Name Pass type Value type Default value Description
$load_balancing_group by value string

The name of the load balancing group, from which the shard should be randomly picked.

Returns

?\SmartFactory\DatabaseWorkers\DBWorker

returns DBWorker object or null if the object could not be created.

Throws

\Exception

It might throw an exception in the case of any errors.

Authors

Oleg Schildt

Source code


Method: IShardManager::registerShard()

public function registerShard(string $shard_name, array $parameters, string $load_balancing_group = ""): bool;

Registers a new shard.

Parameters

Name Pass type Value type Default value Description
$shard_name by value string

Unique shard name.

$parameters by value array

The connection parameters to the shard as an associative array in the form key => value:

  • $parameters["db_type"] - type of the database (MySQL or MSSQL)

  • $parameters["db_server"] - server address

  • $parameters["db_name"] - database name

  • $parameters["db_user"] - user name

  • $parameters["db_password"] - user password

  • $parameters["autoconnect"] - should true if the connection should be established automatically upon creation.

  • $parameters["read_only"] - this parameter sets the connection to the read only mode.

$load_balancing_group by value string ""

The name of the load balancing group, if the shard should be part of it.

Returns

bool

It should return true if the registering was successful, otherwise false.

Throws

\Exception

It might throw an exception in the case of any errors.

Authors

Oleg Schildt

Source code