AktifPerunding

  • Home
  • About
  • Our Team
  • Portfolio
  • News
  • Contact

categories

  • Civil & Structure
  • Electrical
  • Electronic
  • Information & Technology
  • Mechanical
  • Photovoltaic
  • PHP
  • Programming
  • Solar Power
  • Technology

Yii2: Connection string for different Database Server

Connection string configuration

Admin APSB 14/09/2018 PHP, Programming

Yii2 supports different database server types and each one have its own way to connect to database. To connect with any database we need to prepare DSN for connection.

In this quick tip we are going to see how DSN should be created for different Database servers.

If you are running basic app of Yii2 then you need to make this changes in db.php file under config directory and in case of advance application it should be done in main.php under config directory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

<?php
return [
   'components' =  [
         'db' => [
           'class' => 'yii\db\Connection',
           'dsn' => 'mysql:host=localhost;dbname=my_awesome_db', // MySQL, MariaDB
           //'dsn' => 'sqlite:/path/to/database/file', // SQLite
           //'dsn' => 'pgsql:host=localhost;port=5432;dbname=mydatabase', // PostgreSQL
           //'dsn' => 'cubrid:dbname=demodb;host=localhost;port=33000', // CUBRID
           //'dsn' => 'sqlsrv:Server=localhost;Database=mydatabase', // MS SQL Server, sqlsrv driver
           //'dsn' => 'dblib:host=localhost;dbname=mydatabase', // MS SQL Server, dblib driver
           //'dsn' => 'mssql:host=localhost;dbname=mydatabase', // MS SQL Server, mssql driver
           //'dsn' => 'oci:dbname=//localhost:1521/mydatabase', // Oracle
          'username' => 'DB User Name',
          'password' => 'Password for selected user',
          'charset' => 'utf8',
        ]
     ];
];


?>

AktifPerunding

DISCLAIMER: We are not responsible for any lost or corrupt personal data information when using this website

information

CONSULT . DESIGN . BUILD

Tel: +603 8959 3901

Email: aktifperunding@gmail.com

Working Hours: 9AM-5PM (+8 GMT)

Instagram

© Copyright Aktif Perunding Sdn. Bhd. All Rights Reserved

Powered by Maximum Builders