php fatal error- no idea why
im getting this error message
Fatal error: Cannot redeclare get_db_conn() (previously declared in `/home/maxer/domains/x/public_html/xmasapp/dbfuncs.php:21) in /home/maxer/domains/x/public_html/xmasapp/dbfuncs.php on line 24`
this is the code
function get_db_conn() {
$conn = mysql_connect($GLOBALS['db_ip'], $G开发者_如何转开发LOBALS['db_user'], $GLOBALS['db_pass']);
mysql_select_db($GLOBALS['db_name'], $conn);
return $conn;
}
line 21 refers to
$conn = mysql_connect($GLOBALS['db_ip'], $GLOBALS['db_user'], $GLOBALS['db_pass']);
line 24 is the closing curly bracket of the function
the code worked fine until I tried to clean my code up, I ripped most of the "view" code out and put it into separate files but didn't change any logic
You are most likely including a file twice or including two files that include the same file each.
You can prevent this by using include_once() or setting up a better structure of what you include when.
EDIT
Try this and see if you see an error in your include setup.
echo "<pre>";
print_r(get_included_files());
echo "</pre>";
Somewhere you're including a file twice or some two files has a definition of your function.
Is this in an includes file? Is the includes file getting included more than once?
It's complaining because the get_db_conn is defined more than once, and most likely it's getting included multiple times unless you have that function in two different places.
Your error message says:
Cannot redeclare get_db_conn() (previously declared in [...]/dbfuncs.php:21) in [...]/dbfuncs.php on line 24
You have a function named get_db_conn()
that you are declaring multiple times. Is your dbfuncs.php
file including itself?
It's possible you're include()ing the same file more than once. For this reason I like to use include_once() whenever possible.
You declare two functions with identical names (both are called get_db_conn())
精彩评论