PHP Help - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Skype & Technology (/forumdisplay.php?fid=9) +---- Forum: Tech Talk (/forumdisplay.php?fid=17) +----- Thread: PHP Help (/showthread.php?tid=53145) PHP Help by DragonX on 11-21-2005 at 05:41 AM
Alright, i'm making my own site in wish i use php/mysql so therefore i need to make a connection. Since my connection details changes from my pc to my host i though of making a conn.php file to include in my other files which i could change. It looks something like this... code: other.php code: but when i do: code:it gives an error that $conn isn't declared. So i was just looking for some insight, or if there's a better way of doing it. Thx in advance RE: PHP Help by ipab on 11-21-2005 at 06:57 AM
i believe that once you are including conn.php you dont need to keep connecting to the db over and over again, therefore code: should actually be code: and acutally even in conn.php remove $conn from code: RE: PHP Help by Ezra on 11-21-2005 at 07:49 AM
connection.inc.php code: index.php code: That's how I always do it with my websites. EDIT: Added the mysql_query bit. RE: PHP Help by J-Thread on 11-21-2005 at 09:15 AM
A better way to do it: code: Include this in all your scripts (I always make an include file in which I include everything) and when you need to acces the database just do: code: The code will never make more then 1 database connection, wil never make a connection when you don't need it, AND it works with multiple connections. Just be sure you doesn't use $database somewhere else in the script, and off course use query instead of mysql_query everytime. Besides that, you can better use require instead of include, because you're sure your scripts need the database... So if the file doesn't exist your script doesn't need to be executed. RE: PHP Help by DragonX on 11-21-2005 at 09:15 AM
Ah ha, it works RE: PHP Help by ipab on 11-21-2005 at 04:37 PM
thats some handy code there J-Thread RE: PHP Help by J-Thread on 11-21-2005 at 05:29 PM
That's why we're here, to learn things. |