Configuring Database Settings



Before using database methods, you need to make a number of settings. In this section, we gave you information on what kind of settings to make. Below are the Database Platforms supported by the ZN Framework. Below is the contents of the configuration file.

File: Config / Database.php
Data Type Key Explanation Drivers using
String $ driver = 'mysqli' The database to be used is used to select the platform. All
Options mysqli , postgres , sqlserver , oracle , odbc , pdo
String $ host = 'localhost' Used to determine the host name of the database platform. All
String $ Database Used to specify the name of the database to which the connection will be made. All
String $ user = 'root' It is used to specify the user name of the database to be connected. All
String $ password Used to specify the password information of the database to be connected. All
String $ DSN Generally, the PDO is set connection settings used to create links to sub-drivers. This setting allows you to provide a connection without using other settings for PDO sub drives. This means that the operation of other connection settings can be performed alone. oracle
odbc
postgres
pdo
String $ Server The server connection is a valid setting for the drives that require it. odbc
sqlserver
Int $ port The port connection is a valid setting for the drivers that need it. postgres
sqlserver
pdo
String $ cacheDriver = 'file' If the Select queries will be cached, which driver will be used. All
Bool $ queryLog = false Inquiries will be taken under log records. All
Bool $ pconnect = false The permanent connection will not be turned on or off. postgres
sqlserver
oracle
odbc
Bool $ encode = false The Encode setting is for the drivers that need it. SQLServer
String $ prefix You can use this setting to avoid continuation prefixes for table uses in databases with table prefixes. All
String $ charset = 'utf8' Used to set the database character set. All
String $ collation = 'utf8_general_ci' The database is used to set the character encoding pattern. mysqli
pdo
Array $ differentConnection = [] At the same time, it is used in situations where it is necessary to work with multiple platforms and databases. You can create as many different database connections as you want by creating multiple sets of settings for this setting. The DB :: differentConnection () method of the Database library is used to use the set of settings defined here . All

 

 

# Different Connection


If you are going to use more than one hard link, these settings the differentconnectio you can add connection groups as follows.

'differentConnection' =>
[
    'mysqlConnect'         => 
    [
        'database' => 'test1'
    ],
    'postgresPanelConnect' => 
    [
        'driver'   => 'Postgres', 
        'database' => 'panel', 
        'password' => 1234
    ],
    'postgresSiteConnect'  => 
    [
        'driver'   => 'Postgres', 
        'database' => 'site' , 
        'password' => 4321
    ]
]
Using the Setting Set

As seen above, different sets of settings have been created. To receive connections from this set of settings;

$mysqlConnect         = DB::differentConnection('mysqlConnect');
$postgresPanelConnect = DB::differentConnection('postgresPanelConnect');
$postgresSiteConnect  = DB::differentConnection('postgresSiteConnect'); 
$panelGet = $postgresPanelConnect->get('accounts');

.

Parametric Configuration

If you want to make different settings without using the set of parameters, you can use parameter 1 of the method in the array type.

$different = DB::differentConnection
([
    'database' => 'newDatabase', 'driver' => 'pdo:mysql'
]);
Configuration with Config Library

Set the database settings in the startup files, in the initial controller, or just before the database commands config class.

Config::set('Database', 'database',
[
    'driver'   => 'pdo:mysql',
    'database' => 'my_database',
    'user'     => 'my_user',
    'password' => 'my_password'
]);

$result = DB::get('my_table')->result();

This usage is very useful in dealerships and similar projects.

 

 

# Sample Links by Driver


Below are the connection usages required by the driver.

MySQLi Connection
'driver'    => 'mysqli',               // Required
'host'      => 'localhost',            // Required
'database'  => 'exampleDatabaseName',  // Required
'user'      => 'databaseUserName',     // Required
'password'  => 'databaseUserPassword', // Relative
'port'      => '',                     // Relative
'prefix'    => 'tablePrefix',          // Relative
'collation' => 'utf8_general_ci',      // Relative
'charset'   => 'utf8'                  // Relative
PDO MySQL Connection
'driver'   => 'pdo:mysql',
'dsn'      => 'mysql:host=localhost;port=3307;dbname=testdb',
'user'     => 'databaseUsername', 
'password' => 'databasePassword'
Postgres Connection
'driver'    => 'postgres',             // Required
'host'      => 'localhost',            // Required
'database'  => 'exampleDatabaseName',  // Required
'user'      => 'databaseUserName',     // Required
'password'  => 'databaseUserPassword', // Relative
'port'      => '1111',                 // Required
'prefix'    => 'tablePrefix',          // Relative
'collation' => 'utf8_general_ci',      // Relative
'charset'   => 'utf8',                 // Relative
'pconnect'  => false                   // Relative 
SQLite Connection
'driver'    => 'sqlite',               // Required
'database'  => 'exampleDatabaseName',  // Required
'password'  => 'databaseUserPassword', // Relative
'prefix'    => 'tablePrefix'           // Relative
SQLServer Connection
'driver'      => 'sqlserver',             // Required
'server/host' => 'serverName/sqlexpress', // Required
'database'    => 'exampleDatabaseName',   // Required
'user'        => 'databaseUserName',      // Required
'password'    => 'databaseUserPassword',  // Relative
'port'        => '1452',                  // Required
'prefix'      => 'tablePrefix',           // Relative
'encode'      => true,                    // Relative
'charset'     => 'UTF-8',                 // Relative
'pconnect'    => false                    // Relative
ODBC Connection
'driver'    => 'odbc',                 // Required
'host'      => 'localhost',            // Required
'server'    => 'serverName',           // Required
'database'  => 'databaseName',         // Required
'user'      => 'databaseUserName',     // Required
'password'  => 'databaseUserPassword', // Required
'prefix'    => 'tablePrefix',          // Relative
'pconnect'  => false                   // Relative

Link with DSN

Or you DSNcan substitute the above settings .

'dsn' => 'Driver={SQL Server Native Client 10.0};Server=swname;Database=dbname;'
Oracle Connection
'driver'      => 'oracle',                // Required
'dsn/host'    => 'localhost/XE',          // Required
'user'        => 'databaseUserName',      // Required
'password'    => 'databaseUserPassword',  // Required
'prefix'      => 'tablePrefix',           // Relative
'charset'     => 'UTF-8',                 // Relative
'pconnect'    => false                    // Relative