Jump to content

Best Practise?


blueman378

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.