After learning thinkPHPC and V's last database operations, I felt like I was using the PDO provided by PHP. Now thinkPHP also has a set of database operation classes. I looked at the tutorial and it was complicated to study again .. All the value passing formats have been recorded. I have learned classMy... and learned the operation database of thinkPHP C and V,
The PDO that comes with php I learned earlier will also be used,
Now thinkPHP also comes with a set of database operation classes.
I looked at the tutorial and it was complicated to study again ..
I learned the class MySQLi, and later I learned how to use pdo and pdo. Now I have another M... I want to learn more.
I will ask if thinkPHP's big M method is used much in your project?
Is it more convenient than pdo?
I still want to learn ..
Reply content:
After learning the operation database of thinkPHP C and V,
The PDO that comes with php I learned earlier will also be used,
Now thinkPHP also comes with a set of database operation classes.
I looked at the tutorial and it was complicated to study again ..
I learned the class MySQLi, and later I learned how to use pdo and pdo. Now I have another M... I want to learn more.
I will ask if thinkPHP's big M method is used much in your project?
Is it more convenient than pdo?
I still want to learn ..
- 27 minutes ago
- Comment
- Reply
Please log on first and then comment
Sort by default
Five answers
The answer is helpful to people and has reference value.0The answer is not helpful. It is a wrong answer.
After reading the document, you will feel very convenient to use. What is the significance of the framework ?! Isn't that about letting you write less code! In other words, the tp 3.2.3 database driver is rewritten with pdo (fully pdo-based)
Now that you want to use the Thinkphp framework, you must first use the M or D method!
-
If you want to instantiate the model class file, use D
-
If you do not need to load model classes, use M
Generally, this is simple.CURDUse M. Use it based on actual conditions. Hope to help you
Thinkphp has two model calling methods: M () and D (), for example, operating the user table:
M('user')->add(array('name' => 'zhangsan'));D('**U**ser')->add(array('name' => 'lisi'));
Note that the first letter of User in D ('user') is capitalized. The difference between the two is that D () can be used by you to write extension model operations, while M () is the built-in method of thinkPHP, that is, D () can implement function expansion, the M () function cannot be expanded, and the performance of D () is weaker than that of M.
You must understand the pdo and mysqli methods when learning PHP, but in a specific project, use the thinkPHP encapsulated method to perform operations.
I use D more
Databases are used in almost every project.ThinkPHPIn this framework, a table is encapsulated into an object. In php, Object Instantiation requires a new class, and the code is similar
// Similar to MysqlTableClass $ obj_Table = new MysqlTableClass ('db _ name', 'table _ name'); obj_test = $ obj_Table-> getOne ();
WhileThinkPHPOfMFunction (here I have to correct your statement. It is called a method in the class,This M is located in a public function, so it can only be called a function.), Encapsulates the new operation above, and returns an object directly.
Skill development
Do not useMMethod, because when you need to add a custom model later,MThe method must be changed one by oneD, It is very troublesome, And if you directly useDTo avoid such problems.
To sum up
Simply use the D method, which is essentially an encapsulation ~