CAN302 – Technologies for e-commerce Lab 2
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CAN302 – Technologies for e-commerce
Lab 2 – PHP and Database
Aim
The aim of this lab is to learn how to handle database through different tools.
Tips:
1. If you are not sure why you are doing something, ask a TA. This is what they are here for.
2. The M-Dev-Store online videos are good references while our labs have different focus. If you want to be an expert, you are recommended take both labs and on-line videos.
3. The forums @ LMO are available for questions and discussions.
4. These labs are expected take more than the 2 allocated hours. You should complete them in your own time before the next lab. Practice makes perfect!
Database and MariaDB:
1. A collection of related pieces of data, whose purpose is to solve the data management needs of an institution is called a Database. Database Management Systems (DBMS), on the other hand, are very complex software that save the data on the secondary storage devices and which are used to manipulate databases. SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in a relational database. Though there are many different DBMS like Oracle, MariaDB, MySQL, SQL Server …, the SQL is same for all of them. However, the tool used to operate different DBMS is different from each other. “phpMyAdmin” is a web tool that can operate MariaDB. We can use it to create database, table
and Create (insert), Read (query), Update, Delete data or CRUD.
Let’s make the 1st demo as following:
In above, we get data from database and show them as a table in the webpage. There are two buttons: by “add”, we can add new data into database; by “search”, we can filter the result in the table by conditions.
First of all, we need to create a database and then a table to hold such data. We can use “phpMyAdmin” for that purpose. The data structure is as:
In above, a database named “ lab2” was created and a table named “user” was created with four columns: id, first_name, last_name and email.
To show the content on the webpage as the demo, the html part code is as:
From line62 to line72 are PHP code, the dynamic data are retrieved from database and output to the html by using “while” loop.
To interact with server, there are mainly two methods: GET and POST. GET method is used to appends form data to the URL in name or value pair. If you use GET, the length of URL will remain limited. It helps users to submit the bookmark the result. GET is better for the data which does not require any security or having images or word documents. POST is a method that is supported by HTTP and depicts that a web server accepts the data included in the body of the message. POST is often used by World Wide Web to send user generated data to the web server or when you upload file. To use POST method, we need to use the
2023-03-28
PHP and Database