<?php
/*$servername = "localhost";
$username = "yrgbsnew";
$password = "6BAot]h]{O]B";
$dbname = "all_iccplus";
*/

$servername = "localhost";
$username = "yrgbs";
$password = "(5gVtQ6=h.Hs";
$dbname = "iccplus";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

/*
$conn= [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=iccplusnew',
    'username' => 'yrgbs',
    'password' => 'YRGbs123',
    'charset' => 'utf8',
    'tablePrefix' => 'cms_',
];
return $conn;
*/

$sql = "SELECT dbname FROM cms_dbchange where sitetype='all' ORDER BY id DESC LIMIT 1 ";
$result = $conn->query($sql);

if ($result->num_rows == 1) { // more than one connection should never happen!
    $row = $result->fetch_assoc();
    $connection = [
        'class' => 'yii\db\Connection',
       // 'dsn' => $row["dsn"],
		'dsn' => 'mysql:host=localhost;dbname='.$row["dbname"],
        'username' => 'yrgbs',        
		'password' => '(5gVtQ6=h.Hs',
        'charset' => 'utf8',
		'tablePrefix' => 'cms_',
    ];  
} else {
    die("Error more than one connection found");
}
$conn->close();
return $connection;
