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.

dk007
  • 79
  • 2
  • 9
  • 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`). – arkascha Jun 24 '16 at 16:19
  • You could have a look here: [PHP database connection class](http://stackoverflow.com/questions/3228694/php-database-connection-class) – Nico Orfi Jun 24 '16 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. – Sammitch Jun 24 '16 at 16:53
  • Thanks for your suggestions everyone – dk007 Jun 24 '16 at 19:51

0 Answers0