Developing a Model-View-Controller Component for Joomla Part 3

Slides:



Advertisements
Similar presentations
What is MySQL? MySQL is a relational database management system (A relational database stores data in separate tables rather than putting all the data.
Advertisements

Access Lesson 2 Creating a Database
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1 Created By Martin Schedlbauer
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Session 5: Working with MySQL iNET Academy Open Source Web Development.
CPSC 203 Introduction to Computers T59 & T64 By Jie (Jeff) Gao.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Introduction to MySQL Lab no. 10 Advance Database Management System.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
SQL introduction. RHS – SOC 2 Getting data out of databases Databases are ”just” containers of data We could – in principle – just put data in a text.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Component 4: Introduction to Information and Computer Science Unit 6a Databases and SQL.
Microsoft Access. Microsoft access is a database programs that allows you to store retrieve, analyze and print information. Companies use databases for.
O FFICE M ANAGEMENT T OOL - II B BA -V I TH. Abdus Salam2 Week-7 Introduction to Query Introduction to Query Querying from Multiple Tables Querying from.
SQL introduction. SWC Getting data out of databases Databases are ”just” containers of data We could – in principle – just put data in a text.
CHAPTER 1 – INTRODUCTION TO ACCESS Aliya Farheen March 5, 2014.
Database Objective Demonstrate basic database concepts and functions.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
Android - SQLite Database 12/10/2015. Introduction SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
1 Working with MS SQL Server Beginning ASP.NET in C# and VB Chapter 12.
Data Resource Management Application Layer TPS A RCHITECTURE Data Layer Sales/MarketingHR Finance/Accounting Operations Spreadsheet Data MS Access Accounts.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Introduction to Database Programming with Python Gary Stewart
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
ASP.NET Programming with C# and SQL Server First Edition
Query Methods Simple SQL Statements Start ….
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
© 2016, Mike Murach & Associates, Inc.
Database application MySQL Database and PhpMyAdmin
Accsess 2013 Creating Database.
Principles of Software Development
Website Development Basics with PHP MySQL
Dead Man Visiting Farrokh Alemi, PhD Narrated by …
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Access Lesson 2 Creating a Database
Developing a Model-View-Controller Component for Joomla Part 2
Access: Access Basics Participation Project
Chapter 10 ADO.
Computer Science Projects Database Theory / Prototypes
Database Fundamentals
Developing a Model-View-Controller Component for Joomla
Introduction To Structured Query Language (SQL)
Introduction to Access
Topic 12 Lesson 2 – Retrieving Data with Queries
Handling Data in PL/SQL Blocks
Presentation transcript:

Developing a Model-View-Controller Component for Joomla Part 3 Using a Database

Introduction In the first two tutorials, we showed you how to build a simple model-view-controller component. We had one view which retrieved data from a model (which was created in the 2nd tutorial). In this tutorial, we will be working with the model. Instead of the data being hard coded in the model, the model will retrieve the data from a table in the database. This tutorial will demonstrate how to use the JDatabase class to retrieve data from the database.

Retrieving the Data Our model currently has one method: getGreeting(). This method is very simple - all it does is return the hard-coded greeting. To make things more interesting, we will load the greeting from a database table. We will demonstrate later how to create an SQL file and add the appropriate code to the XML manifest file so that the table and some sample data will be created when the component is installed. For now, we will simply replace our return statement with some code that will retrieve the greeting from the database and return it. The first step is to obtain a reference to a database object. Since Joomla! uses the database for its normal operation, a database connection already exists; therefore, it is not necessary to create your own. A reference to the existing database can be obtained using: $db =& JFactory::getDBO();

Retrieving the Data JFactory is a static class that is used to retrieve references to many of the system objects. The method name (getDBO) stands for get DataBase Object, and is easy and important to remember. Now that we have obtained a reference to the database object, we can retrieve our data. We do this in two steps: store our query in the database object load the result

Retrieving the Data Our new getGreeting() method will therefore look like: hello is the name of the table that we will create later, and greeting is the name of the field that stores the greetings. If you are not familiar with SQL, it would be helpful to take a tutorial or a lesson to get yourself up to speed. There are many such tutorials on the web and they are easily found using search engines. The $db->loadResult() method will execute the stored database query and return the first field of the first row of the result.

Creating the Installation SQL File The Joomla! installer has built-in support for executing queries during component installation. These queries are all stored in a standard text file. We will have three queries in our install file: the first will drop the table in case it already exists, the second will create the table with the appropriate fields, and the third will insert the data. Here are our queries:

Creating the Installation SQL File You might find the prefix on the table names rather odd. Joomla! will replace this prefix with the prefix used by the current install. For most installs, this table will become jos_hello. This allows multiple installs of Joomla! to use the same database, and prevents collisions with other applications using the same table names (i.e. two applications might share a database, but might both require a 'users' table. This convention avoids problems.) We have specified two fields in our database. The first field is id, and is called the 'primary key'. The primary key of a database table is a field that is used to uniquely identify a record. This is often used to lookup rows in the database. The other field is greeting. This is the field that stores the greeting that is returned from the query that we used above. We will save our installation queries in a file called admin/install.sql.

Creating the Uninstall SQL File Though we might hope that people will never want to "uninstall" our component, it is important that if they do, nothing is left behind after uninstalling our component. Joomla! will look after deleting the files and directories that were created during the "install", but we must manually include queries that will remove any tables that were added to the database. Since we have only created one table, we only need one query: DROP TABLE IF EXISTS `#__hello`; We will save this uninstall query in a file called admin/uninstall.sql

Updating our XML File We need to change a few things in our hello.xml file. First, we need to add our two new sql files to the list of files to install. Secondly, the SQL install files have to be placed in the admin directory. Thirdly, we need to tell the installer to execute the queries in our files on install and uninstall.

Updating our XML File