多个PHP MySQL更简单的查询与一个更复杂的查询,

时间:2022-09-25 16:43:38

Should I do single more complex MySQL query or multiple simpler queries with PHP?

我是否应该使用PHP进行单个更复杂的MySQL查询或多个简单查询?

For example

例如

Simpler queries:

简单查询:

UPDATE image SET profile = 0 WHERE user_id = 1;

UPDATE image SET profile = 1 WHERE user_id = 1 AND id = 10;

One single more complex query:

一个更复杂的查询:

UPDATE image
    SET profile = CASE id WHEN 10 THEN 1 ELSE 0 END
    WHERE user_id = 1;

1: What is fastest and most efficient?

什么是最快和最有效的?

2: What is considered to be best practice, or preferred method?

2:什么是最佳实践,还是首选方法?

1 个解决方案

#1


1  

One single query is fastest and most efficient

一个查询速度最快,效率最高

Besides the IF statement, MySQL also provides an alternative conditional statement called MySQL CASE. The MySQL CASE statement makes the code more readable and efficient. See more details... http://www.mysqltutorial.org/mysql-case-statement/

除了IF语句,MySQL还提供了另一种条件语句MySQL CASE。MySQL CASE语句使代码更具可读性和效率。看到更多的细节…http://www.mysqltutorial.org/mysql-case-statement/

#1


1  

One single query is fastest and most efficient

一个查询速度最快,效率最高

Besides the IF statement, MySQL also provides an alternative conditional statement called MySQL CASE. The MySQL CASE statement makes the code more readable and efficient. See more details... http://www.mysqltutorial.org/mysql-case-statement/

除了IF语句,MySQL还提供了另一种条件语句MySQL CASE。MySQL CASE语句使代码更具可读性和效率。看到更多的细节…http://www.mysqltutorial.org/mysql-case-statement/