I'm moving a PHP site from development to a production server and testing the new database connection. I have a config.php
page that has only this (but with real data):
<?php
// Database Constants
defined('DB_SERVER') ? null : define('DB_SERVER', 'xxx.xxx.xxx');
defined('DB_PORT') ? null : define('DB_PORT', 'yyy');
defined('DB_USER') ? null : define('DB_USER', 'zzz');
defined('DB_PASS') ? null : define('DB_PASS', 'abcdefg');
defined('DB_NAME') ? null : define('DB_NAME', 'lmnop');
?>
Then I have initialize.php
which holds all of my define()
constants, and calls all of my classes.
<?php
// Define core paths
// DIRECTORY_SEPARATOR is a PHP pre-defined constant
// (\ for Windows, / for Unix)
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null : define('SITE_ROOT', 'http://...etc');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.'/_includes');
// load config file first
require_once(LIB_PATH."/config.php");
etc...
?>
So far, so good. (I'm using URLs and not DIR paths on purpose, btw.)
But when I create a test.ph
p page to run a query, I'm getting an error that DB_SERVER is not found. I can echo something in config.php
and it will appear at the top of the page on test.php
, so it's calling the config.php
file. And here's the real crazy kicker:
When I copy everything from config.php
and paste it into initialize.php
, don't change a thing, and then comment out the config.php
file... the query works. For some reason it just won't let me pull those variable definitions in from config.php
.
Does anyone have any idea why?