As stated above, an .ini file can be no more or less secure than storing it in the .php file itself. However, keep in mind that when using the .ini file, this parameter is global with respect to all PHP codes and websites. Using a .ini file may affect other code for which you want to use a different user.
In general, it is probably best security practice to NOT use a .ini file to store a password, simply because it is now open to anyone who stores PHP files on your server. It also does a bit of a hassle if you suddenly need to provide several sites or applications for different site logins (for individual databases). It is not better to use the same login for several databases, except for the root user, which should be used only for administrative purposes.
source share