Professional Documents
Culture Documents
Salvaña Ruel James - Module 8
Salvaña Ruel James - Module 8
Salvaña Ruel James - Module 8
BSIT 3A
Prepared by:
REYNEL M. MARGELINO
Faculty
Lesson Objectives:
At the end of this lesson, you will be able to:
• Setup XAMPP as local web server
• Learn how to use phpMyAdmin as a free software tool in managing
databases, tables, columns, relations, indexes, users, permissions, etc.
• Learn how to connect flask to mysql database and you can insert the
form data.
• Build a CRUD (Create, Read, Update, Delete) web application with the
integration of HTML, CSS, Python (FLASK) and MySQL.
3.
4. Click MySQL Admin button.
8. Click log-out
CREATE DATABASE AND TABLE
1. Log-in Again to your phpMyAdmin and create database. Click New and
Input desire database name flask_db and press create button
2. Click the database and create the desire table name and numbers of column
and press Create to save Changes
3.
Often this is the primary key field that we would like to be created automatically
every time a new record is inserted.
Code:
a. cd documents
b. cd f2
c. py –m venv env
d. env\Scripts\activate
e. pip install flask
f. pip install Flask-MySQLdb.
Notification:
Running setup.py install for Flask-MySQLdb ... done
Successfully installed Flask-MySQLdb-0.2.0 mysqlclient-1.4.6
5. On your flask folder f2 create new text document save it as main. py and
new folder named templates and that will handle all html file. Copy the
code below for main.py
Note:
mysqlcursor.execute() Method
This method executes the given database operation (query or command). The
parameters found in the tuple or dictionary params are bound to the variables
in the operation. Specify variables using %s or %(name)s parameter style (that is,
using format or pyformat style). execute() returns an iterator if multi is True.
mysqlconnection.commit() Method
This method sends a COMMIT statement to the MySQL server, committing the
current transaction. Since by default Connector/Python does not autocommit, it
is important to call this method after every transaction that modifies data for
tables that use transactional storage engines.
Note: The INSERT INTO statement is used to insert new records in a table.
Copy the code below and save it to insert. html
OUTPUT
8. Inside main.py add the code below for update function
Note: The UPDATE statement is used to modify the existing records in a table.
9. Create new file update.html save it to templates folder.
OUTPUT
10. Inside main.py add the code below for delete function
12. Inside main.py add the code below at the bottom part of the file
OUTPUT
SUMMARY
• SQL stands for Structured Query Language lets you access and
manipulate databases.
• In SQL auto-increment allows a unique number to be generated
automatically when a new record is inserted into a table.
• mysqlcursor.execute() is a method executes the given
database operation (query or command).
• mysqlconnection.commit() is a method that sends a commit statement to
the mysql server, committing the current transaction.
• The INSERT INTO statement is used to insert new records in a table.
• The UPDATE statement is used to modify the existing records in a table.
• The DELETE statement is used to delete existing records in a table.
• The SELECT statement is used to select data from a database.
QUESTIONNAIRE
TRUE OR FALSE
Instructions:
✓ Shade the letter A if your answer is True and B if False on the answer on the
separate sheet.
MULTIPLE CHOICE
Instructions:
✓ Write the letter of the correct answer on the separated sheet.
✓ Choose the best answer
10. is a method that sends a COMMIT statement to the
MySQL server, committing the current transaction.
A. MySQLCursor.execute() Method
B. MySQLConnection.commit() Method
C. SQL Command
D. CRUD
E. None of These