Mysql VIEWS 与 PHP 查询

编程入门 行业动态 更新时间:2024-10-24 06:34:38
本文介绍了Mysql VIEWS 与 PHP 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在开发一个 Web 应用程序,该应用程序涉及在各种列表中创建餐厅列表,例如Joe 必须访问的地方".现在对于每个餐厅和列表,我在网站上显示了计算

I am working on a web application which involves create list of Restaurants in various lists like "Joe's must visit places". Now for each Restaurant and list, I have display on website which calculates

计算餐厅的受欢迎程度列表的受欢迎程度餐厅所在的列表数量

目前我正在 PHP 中使用 MySQL 语句,但计划切换到 MySQL VIEWS 并在 PHP 中执行一个简单的选择语句...

Currently I am using MySQL statements in PHP for this but planning to switch to MySQL VIEWS and do a simple select statement in PHP...

我的问题是,在 PHP 中使用 VIEWS 编写 sql 查询的优点/缺点是什么?

推荐答案

使用视图增加了抽象级别:您以后可以更改表的结构,而不必更改显示有关列表信息的代码,因为您仍将查询视图(尽管视图定义可能会更改).

Using views adds a level of abstraction : you may later change the structure of your tables, and you will not have to change the code that displays the information about the lists, because you will still be querying the view (the view definition may change, though).

主要区别在于每次插入后都会更新视图,这样每当您查询视图时数据就准备好",而使用自定义查询将使 MySQL 每次都计算所有内容(当然有一些缓存).

The main difference is that views are updated after each insertion, such that the data is "ready" whenever you query the view, whereas using your custom query will have MySQL compute everything each time (there is some caching, of course).

最重要的是,如果您的列表更新频率低于查看频率,您会发现使用视图的性能有所提升.

The bottom line is that if your lists are updated less frenquently than they are viewed, you will see some gains in performance in using views.

这篇关于Mysql VIEWS 与 PHP 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 02:23:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/901390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Mysql   VIEWS   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!