10
How do I open a configuration file, rewrite the value of an array, and close and save the file? Example: config.php
return Array {
'DB_TYPE' => 'mysql',
'DB_USER' => 'root'
}
config.php (After function execution):
return Array {
'DB_TYPE' => 'pgsql',
'DB_USER' => 'root'
}
Note that DB_USER was not affected. Could use fopen(), fwrite() and fclose() to do this, but would end up losing the other arrays.
The fuelphp framework has this function (save()): http://fuelphp.com/docs/classes/config.html
I’m not using any framework .
Do you want to persist the data? You will have to use a database or save the settings to a file. It is possible to store the data using Session (http://php.net/manual/en/features.sessions.php), but when you close the browser the session is destroyed and the value of the array returns to the initial value.
– Filipe Moraes
what I understood is that it has a command that when running it wants to modify the bd configuration file and save the file with a different attribute.
– Skywalker
That’s right @Skywalker
– user28062
I don’t understand ... explain better this scheme of reading/recording the file that Skywalker commented.
– rray
Without time to come up with an answer, I will try to explain what I understood, it has a configuration file, that inside ta saved this code
return array (
 'DB_TYPE' => 'mysql');
at a certain point he wants to modify this file and change where it ismysql
forpgsql
);– Skywalker
This
return array (
 'DB_TYPE' => 'mysql'
);
it seems to me that the of some framework. Tell me Voce can not manually edit the configuration file?– Guilherme Nascimento
This question is being discussed here: http://meta.pt.stackoverflow.com/q/4295/3635
– Guilherme Nascimento
Good evening, I still don’t understand if you’re using fuelphp or not, could you be clearer? You want to change the values of these configuration files, and a system that you are creating? How does this system work? What is your exact goal?
– Guilherme Nascimento
Yes, it is a Class that I am developing; its goal is to obtain, set and save the configuration file. I’m not using Fuelphp, I just gave an example of which framework has a similar function
– user28062
Got an answer? the config file has the tag
<?php
?– h3nr1ke
You invented this keyed array structure ? Because array in PHP exists in two ways:
return array('chave'=>'valor')
andreturn ['chave'=>'valor']
(version 4.5 or >)– Ivan Ferrer