0

I may be asking this question wrong but I'm having trouble finding any specific answers. In most examples of the MySQL PDO I see, it's being used with functions for example:

 function getContent() {.....} 

So my question is.... is the PDO I see being structured this way for security purposes or is it for other reasons such as cosmetic and or to prevent repetition etc?

1
  • You mean, as opposed to copy-pasting the connection code every time you want to use it? Most people use a class for database operations - you can easily store the connection in a private static property, for instance. Commented Aug 6, 2016 at 23:03

1 Answer 1

1

Code ran in a function is scoped to that function, so parameters are encapsulated (i.e., not global). Apart from that, there's no real benefits to security. It's the same as executing the code from anywhere else. Most people use methods to organise code for reusability and to avoid repetition more than anything.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Nick that is what I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.