PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
require 'config.php';
function mysqlConnect()
{
global $db_host, $db_username, $db_password, $db_database;
$connection = mysql_connect($db_host, $db_username, $db_password)
or die('Failed to connect to MySQL. '.mysql_error());
$db = mysql_select_db($db_database, $connection)
or die('Failed to select the database.');
return $connection;
}
On my local server, this works perfectly fine. On the dev server it will not get the $db_* variables from the config file. Is there a php setting I need to change to get this to work? AFAIK, this is a documented feature in the php manual. Don't make me explain, but my local server is php4 because our production server is php4...but our dev server is php5.
Is your config.php file in lowercase?
This sometimes happens when smth works ok on local (windows - case-insensitive os) and not working on server (usually case-sensitive linux).
I'd also advise not to use global vars - as it is bas coding style.
In this case you can define constants:
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'my_db');
define ('DB_USER', 'my_name');
define ('DB_PASS', 'my_pass');