Forum Moderators: coopster
I have a file called 'myfile.php' that has an include statement to include the file 'functions.php'. 'functions.php' contains a function called 'dbconnect', which connects to a database.
I keep getting:
'error: Call to undefined function: dbconnect() in ...myfile.php'
I know the file functions.php is being found though because I put the word 'test' at the beginning of it, and it shows up when viewing .myfile.php'. If I copy and paste the function 'dbconnect' into 'myfile.php' everything works fine, so there is nothing wrong with the function itself. It just can't be found when it is in the included file, 'functions.php'.
I keep thinking I'm missing something obvious here. It's been a long time since I've done any php/mysql coding, so maybe I've forgotten something really basic. (I did remember to upload in ASCII though.) Could it be some permissions problem with the file 'functions.php'? Anyone have any guesses at what might be causing this?
include ("http://www.mydomain/functions.php")
I changed it to a relative path like this:
include ("../../../functions.php")
and now it works! I had no idea it needed to be done that way. I decided to try it only because that was how I did it for another site a couple of years ago.
Thanks for the suggestion though coopster, I did call the includes file before I tried to execute the dbconnect() function though.
I do have a follow up security question though, if anyone is reading this. I've forgotten, but are there security issues with the functions.php file containing the db password, etc.? Should the permissions for that file be set to 755 or something? Or is best to place that file outside of the directory where the regular html files are?