开发者

Using MySQL views in PHP applications

开发者 https://www.devze.com 2022-12-14 02:56 出处:网络
I have a three tables in an applicatio开发者_Go百科n and I need to perform a query which joins all three of them on a regular basis.Chances are that all three of these tables will be updated often.

I have a three tables in an applicatio开发者_Go百科n and I need to perform a query which joins all three of them on a regular basis. Chances are that all three of these tables will be updated often.

I'm considering using a view to avoid having to use the verbose join syntax in several places within my code. Would this be a suitable options? I have not used views in a large scale application before and am unsure of the effects they will have on performance (positive or negative).

Any advice would be greatly appreciated.

Thanks.


In MySQL a view is generally executed only when it's requested, so it's almost the same like writing the jong query or executing a query on the view, so in my experience you shouldn't hit any performance problems as long as the join query is fast as well.


MySQL views are relatively new but this in my opinion would be a suitable option. Test your query by prefixing it with an EXPLAIN.


Using a database view to eliminate code replication does not seem like the proper thing to do. You should instead consider refactoring your code.

Doing as suggested would still mean replicating the call to the view several times in your code. Which is bad practice IMHO.

0

精彩评论

暂无评论...
验证码 换一张
取 消