Dare you ask me whether the static method or non-static method should be used when php connects to mysql? Solution

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.