Preamble
I tried to make sure this question was not asked before. I'm new to using StackExchange so I may have failed in doing so. I don't mind rebukes; thick skin and I learn fast :)
THE PROBLEM
I wrote a function and placed in my theme's functions.php
function serverConnect() {
$serverAccess = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$serverAccess) {
die("Access Denied");
}
return $serverAccess;
}
The idea was to be able to have the ability to log into the DB abstracted to a function so whenever my unconventional theme needed it I could log in and do what needed to be done.
As I built more functions, I felt it would be advantageous to break off some functionality into external php files. This script is called when a form is posted in the admin cp.
In theme-root/scripts/hypothetical-theme-function.php:
$switch = mysql_select_db( 'differentDB', serverConnent());
The problem here is that hypothetical-theme-function.php has no access to functions.php to be able to call serverConnect();
I've tried include(/path/to/functions.php), include_once(/path/to/functions.php), require(/path/to/functions.php) and require_once(/path/to/functions.php). The errors I get with the once commands is:
Fatal error: Call to undefined function serverConnent() ...
The problem I get with include or require is:
Fatal error: Cannot redeclare serverConnect() ...
THE QUESTION
How do I call any function in Functions.php from an external php script?