I have a page, index.php, that includes a function.php file at the beginning which contains the following two functions function g_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') { global $$link; if(USE_PCONNECT == 'true') { $$link = mysql_pconnect($server, $username, $password); } else { $$link = mysql_connect($server, $username, $password); } if ($$link) mysql_select_db($database); return $$link; } function g_db_query($query, $link = 'db_link') { global $$link; if(defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) { error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); } $result = mysql_query($query, $$link) or g_db_error($query, mysql_errno(), mysql_error()); if(defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) { $result_error = mysql_error(); error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); } return $result; } Code (markup): The page itself contains the code g_db_connect() or die('Could not connect to the Database'); $manu_sql = 'SELECT * FROM '.TABLE_PREFIX.'manu'; $manu_query = g_db_query($manu_sql); Code (markup): But when I try to access the page I get the error message 1046 - No database selected Why isn't it selecting the database? I've verified that the constants contain the values they are supposed to contain.
Add following line; define( 'DB_DATABASE', 'YOUR DATABASE NAME HERE'); Code (markup): (replace YOUR DATABASE NAME HERE with your actual mysql database name) _before_ calling following line; g_db_connect() or die('Could not connect to the Database'); Code (markup):