Jump to content

Recommended Posts

hi guys, well me and my mate are having a debate and i need your help to win it so:

 

what is the best practise when it comes to mysql,

 

have a file database.php which contains the mysql database/username/password info ect and also opens the connection and include that on every page, and dont clsoe the connection,

 

or every time you need to run a mysql query enter then information and close the connection as soon as the query is finished?

 

 

please state your answer and reasons why

Link to comment
https://forums.phpfreaks.com/topic/107762-best-practise/
Share on other sites

While the connection does get closed when the script stops executing, I think it's a poor practice to expect this to happen. I guess for me it's sorta like the whole magic_quotes thing. Just because the server can attempt to escape poor data... doesn't mean it's doing it right.

 

But yes, neither would be my answer. I would definitely create a class to manage it and pass the object around. One reason is for simple abstraction. Say you're using the native mysql functions and suddenly they change to mysqli... whoops! Now you have 15,000 occurences of mysql that have to be replaced in 65 different files. That's the suck. If you manage this through a class you make that change in one location. There are lots of reasons that make this method beneficial, this is just one example.

Link to comment
https://forums.phpfreaks.com/topic/107762-best-practise/#findComment-553197
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.