简体   繁体   English

如何从Joomla 3中的MySql获取数据

[英]How to fetch data from MySql in Joomla 3

I'm developing a component and trying to call data from DB. 我正在开发一个组件并尝试从DB调用数据。 I can see some different ways to implement that data call. 我可以看到一些不同的方法来实现该数据调用。 Some components use a straightforward select + where + loadObject to retrieve the data, and some use JTable to do that, like Lendr . 有些组件使用直接的select + where + loadObject来检索数据,有些组件使用JTable来做这些,比如Lendr

What is the recommended way to fetch data in Joomla, and is there any tutorial for JTable with J3? 在Joomla中获取数据的推荐方法是什么,是否有任何JTable与J3的教程?

I use below method for few reason. 我使用以下方法的原因很少。

http://docs.joomla.org/Accessing_the_database_using_JDatabase/3.1 http://docs.joomla.org/Accessing_the_database_using_JDatabase/3.1

rather than using JTable it has more customisation options. 而不是使用JTable它有更多的自定义选项。 You can build your queries just like you want to. 您可以按照自己的意愿构建查询。

Also I use JTable for basic CRUD queries. 我也使用JTable进行基本的CRUD查询。 By using a mix you can get done more work by doing less. 通过使用混合,您可以通过减少工作来完成更多工作。

I'd say it depends on what you need. 我会说这取决于你需要什么。 JTable usually loads a whole table row with all its columns. JTable通常会加载整个表行及其所有列。 If that is what you need, then you can use this. 如果这就是您所需要的,那么您可以使用它。 In the administration section, this is often enough all you need. 在管理部分,这通常足以满足您的所有需求。

In frontend however, you usually want to fetch data from different tables using joins, then you'd use your own query using the query builder. 但是,在前端,您通常希望使用连接从不同的表中获取数据,然后使用查询构建器使用您自己的查询。 Docpage is here: http://docs.joomla.org/Accessing_the_database_using_JDatabase Docpage在这里: http ://docs.joomla.org/Accessing_the_database_using_JDatabase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM