Globals are indeed a bad thing. They are old and full of security issues as well as being nearly impossible to debug. Stay away from them at all costs. Instead, pass those variables as a parameter into any function that needs them and have the function return any modifications if necessary. Once you start learning OOP then you can use class properties in place of globals, but parameter injection is the only solution for procedural programming. Well, you could also use constants, but you don't want to go flashing your password into the global scope that way. At least, I'm pretty sure that is a bad idea. It sounds bad... My experience with security and SQL databases is a bit limited, so you might want clarification here. Database names and non-sensitive information should make fine constants though.
Speaking of constants, typically that is what config files are for. For storing site constants so that they can be reused. You
define() a constant by giving it a name, conventionally in caps separated by underscores, and a value and use it almost the same way as a variable, except without the
$. For example:
define( 'DB_NAME', 'name' );
$info[ 'database' ] = DB_NAME;
Another problem here is that you are not using those globals even though you went to all the trouble of making them. Instead, you immediately wrap them into an associative array. This seems kind of redundant. What's wrong with using the variables as they are? You don't appear to be using that
$info array anywhere else and besides adding clutter, you are just making your code harder to read by using longer instances of the same data.
Finally, in regards to your problem, you could use your .htaccess file to advantage, but this really depends on the situation. I would not use this for database connections as it would enforce that connnection on EVERY page, which does not seem necessary. It would be helpful in including the config file in every page though, which is why I mention it.
php_value auto_prepend_file "config.php"
As I said, I would not recommend the above for database connections. If you have a number of pages that require a database connection, I would use a "template" to create this connection, then use specific "views" to do certain tasks. This way you only have to write the code once and you can dynamically change which action is performed. For instance, here is an extremely basic, barebone example. Please don't just copy-paste this, its for demonstration purposes only. Extrapolate from it.
//create db connection
$db;//db should be available in local scope
include $_GET[ 'view' ] . '.php';
$db->stuff();//do some stuff with db
The template is the page you would call, but a GET parameter would define what action to perform by loading another page with the database specific actions to take. Whatever variables are in the local scope in the template will also be available in the local scope on the view. Which is why we are able to use the
$db as if it were a global. Though this is typically frowned upon because, just like globals, it is hard to figure out where those variables are coming from without the proper context. Again, this is just to give you an idea.