Function: dbworker()

function dbworker(array $parameters = [], bool $singleton = true): ?\DatabaseWorkers\DBWorker;

The method dbworker provides the DBWorker object for working with the database.

Details

Currently supported: MySQL und MS SQL.

Parameters

Name Pass type Value type Default value Description
$parameters by value array []

Connection settings 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 paramter sets the connection to the read only mode.

Example:

$dbw = dbworker(["db_type" => "MySQL",
                 "db_server" => "localhost",
                 "db_name" => "framework_demo",
                 "db_user" => "root",
                 "db_password" => "root",
                 "autoconnect" => true
                ]);
$singleton by value bool true

If the parameter is true, it ensures that only one instance of this object exists.

Returns

?\DatabaseWorkers\DBWorker

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

Throws

\Exception

It might throw the following exceptions in the case of any errors.

Authors

Oleg Schildt

Package

Source code