Dare you ask me whether the static method or non-static method should be used when php connects to mysql? Which is better? thank you for choosing solution. ------ Solution -------------------- the dynamic method should be used for the following reasons: 1. static methods can only access static attributes, it may cause inconvenience to other methods. 2. you may use multiple database connections in your application, should I use static or non-static methods when connecting php to mysql?
Which one is better? thank you!
------ Solution --------------------
Yes.
------ Solution --------------------
The dynamic method should be used for the following reasons:
1. static methods can only access static attributes, causing inconvenience to other methods.
2. you may use multiple database connections in your application. when using a dynamic method, you only need to instantiate an object.
3. In most applications, database operations do not exist independently. It is generally encapsulated into a class together with the business logic.