I have my database information file called main-custom.php file which have information in array like this
<?php defined('MW_PATH') || exit('No direct script access allowed');
return array(
// application components
'components' => array(
'db' => array(
'connectionString' => 'mysql:host=localhost;port=3306;dbname=databasebane',
'username' => 'username',
'password' => 'password',
'tablePrefix' => 'mw_',
),
),
// params
'params' => array(
'email.custom.header.prefix' => 'X-Ltxf-'
),
);
Its in Mailwizz.I am looking for get and use this database information in my another file so I have included it in my index.php file like below
<?php
define("MW_PATH","OK");
require_once("../apps/common/config/main-custom.php");
Now I am not getting idea how I can use this database information for create variable like
$connectionString =?
$username =?
.....
Since main-custom.php file returning array, its making me confused and not able to get information from it to my index.php file.
since mailwizz is using main-custom.php as it so I can not modify it. Is there any way to extract required information from it to index.php file without modify it?
Thanks!
4
Answers
I have achieved it using file_get_contents like below
Its working fine as expected. Thanks!
You have two options:
modify the main-custom.php to not return an array and to assign that array to a variable $app = [‘components’ => [..], ‘params’ => [..]] and in the index.php as you write it with require_once you can access the variable $app.
assign $app = ("../apps/common/config/main-custom.php")
you got bunch of problems here:
first of all you can’t just return something in the middle of the file, you need to put it inside a variable to be able to access it, whether its in the same file or you include it
secondly, you can dump what’s inside your array using var_dump() function:
and finally I hope you are aware this is not a database connection, you are just putting database connection string info in a array and passing it to another file, a better way would be to connect to database and pass the connection.
There are two considerations here.
Firstly, the constant
MW_PATH
acts to prevent you from executing the rest of the content, so we need to define that.Secondly, the actual code is just a
return
statement. That only makes sense inside a function or class method, so we need to mock up that environment.This gives us: