0

I have a php file, config.php and it contains following code.

$_config = array(

    'db' => array(
        'mysolidworks' => array(
        'host'      => 'localhost',
        'username'  => 'netvibes',
        'password'  => 'frakcovsea',
        'dbname'    => 'sw_mysolidworks',
        'driver_options' => array(
            PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
        )
    )
  )
);

I want to read this file into a variable and then read the variable like an array. Could anyone help?

2
  • 8
    include(your_file); than use $_config variable Commented Jun 10, 2016 at 18:08
  • thanks a lot @splash58 Commented Jun 10, 2016 at 18:39

2 Answers 2

1

Simply using PHP the way it's meant to work:

include('config.php');
echo $_config['db']['mysolidworks']['host'];
Sign up to request clarification or add additional context in comments.

Comments

0

you can use any of the following

  <?php
        $file_loc = 'SomeDir/config.php';
        require $file_loc; //Throw a fatal if it's not found
        require_once $file_loc; //If this might be called somewhere else in your script, only include it once
        include $file_loc; //Include but just show a warning if not found
        include_once $file_loc; //Include if not already included and throw warning if not
  ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.