I got configuration file database.php
<?php defined('_ENGINE') or die('Access Denied'); return array (
'adapter' => 'mysqli',
'params' =>
array (
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'dbname' => 'db',
'charset' => 'UTF8',
'adapterNamespace' => 'Zend_Db_Adapter',
),
'isDefaultTableAdapter' => true,
'tablePrefix' => 'engine4_',
'tableAdapterClass' => 'Engine_Db_Table',
); ?>
How to get only password from this array?
something like echo $array['password'];
How do I get the array from
database.php?You’ll need to include the file and bind the returned value to a variable, such as in the below example.
$db_confwill contain the data returned by database.php.Documentation
How do I read the specific value from my array?
Since you are working with a nested array the solution is not as far away as you might think. First use
$a[key]to get to the array stored underparams, and then get the value ofpasswordfrom there.As in the below example.
Note: The above is, in a logical sense, equivalent to;
Documentation
I tried the above but it’s just shouting "Access Denied" in my face, why?
To protect database.php from unintended access it has been protected with a check to see so that it’s being used inside of the engine.
The script will
dieif_ENGINEis not defined.If you want to use database.php in a script outside of the thought of engine you’ll need to define the _ENGINE constant before includeing the file.