0

Just wanted to understand that is it a good idea to create a class in PHP which has your connection function?

I tried a bit but realized that i'll have to either include all other functions such as prepare, execute etc in the class itself for it to work or pass the connection object as a parameter every-time i call prepare, execute etc.

What is the best and secure approach for creation a connection to the DB?

Thanks.

4
  • 1
    You are describing an abstraction of an abstraction layer. Rarely a good idea. The classes PHP offers are just fine the way they are (mysqli and PDO). Commented Jun 24, 2016 at 16:19
  • You could have a look here: PHP database connection class Commented Jun 24, 2016 at 16:37
  • 1
    @Nico NO. That post is 6 years old, mysql_* functions are long deprecated, and all the answers are chock full of bad information. PDO and mysqli are already classes full of useful things, use those. Commented Jun 24, 2016 at 16:53
  • Thanks for your suggestions everyone Commented Jun 24, 2016 at 19:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.