SlideShare a Scribd company logo
1 of 28
Learning PHP-MySQL
aadhayan academy of education
By: Akash Gupta
Course Contents
aadhayan academy of education
• Basics of Database
• MySQL
• PHP basics
• HTML/Javascript/CSS basics
• Creating a simple Registration form using
html/php/javascript/css/mysql
• More practicals…
• Project
Scopes of the Course
aadhayan academy of education
After completion of this course, you will:
• Learn PHP and MySQL
• Learn HTML, Javascript and CSS
• Create a Webpage
• Create a Industry-level project
What is Database?
aadhayan academy of education
A database is a separate application that stores a collection of data.
Each database has one or more distinct APIs for creating, accessing,
managing, searching, and replicating the data it holds.
Other kinds of data stores can be used, such as files on the file system or
large hash tables in memory but data fetching and writing would not be
so fast and easy with those type of systems.
So now a days we use relational database management systems
(RDBMS) to store and manager huge volume of data. This is called
relational database because all the data is stored into different tables and
relations are established using primary keys or other keys known as
foreign keys.
A Relational DataBase Management System (RDBMS) is a software
that:
• Enables you to implement a database with tables, columns, and
indexes.
• Guarantees the Referential Integrity between rows of various tables.
• Updates the indexes automatically.
• Interprets an SQL query and combines information from various tables.
RDBMS Terminology
aadhayan academy of education
Before we proceed to explain MySQL database system, lets
revise few definitions related to database.
Database: A database is a collection of tables, with related
data.
Table: A table is a matrix with data. A table in a database
looks like a simple spreadsheet.
Column: One column (data element) contains data of one and
the same kind, for example the column postcode.
Row: A row (= tuple, entry or record) is a group of related
data, for example the data of one subscription.
Redundancy: Storing data twice, redundantly to make the
system faster.
aadhayan academy of education
RDBMS Terminology cont.
Primary Key: A primary key is unique. A key value can
not occur twice in one table. With a key you can find at
most one row.
Foreign Key: A foreign key is the linking pin between two
tables.
Compound Key: A compound key (composite key) is a
key that consists of multiple columns, because one
column is not sufficiently unique.
Index: An index in a database resembles an index at the
back of a book.
Referential Integrity: Referential Integrity makes sure
that a foreign key value always points to an existing row.
An example…
aadhayan academy of education
Student_ID Name Major Grade
101 Shannon BCB A
102 Mike BBMB A
103 Wang MCDB A
… … …
MySQL Introduction
 MySQL is a fast, easy-to-use RDBMS used being
used for many small and big businesses. MySQL is
developed, marketed, and supported by MySQL AB,
which is a Swedish company. MySQL is becoming so
popular because of many good reasons.
 MySQL is released under an open-source license. So
you have nothing to pay to use it.
 MySQL works on many operating systems and with
many languages including PHP, PERL, C, C++, JAVA
etc.
 MySQL is very friendly to PHP, the most appreciated
language for web development.
aadhayan academy of education
Basic MySQL Operations
 Create table
 Insert records
 Load data
 Retrieve records
 Update records
 Delete records
 Modify table
 Join table
 Drop table
 Optimize table
 Count, Like, Order by, Group by
 More advanced ones (sub-queries, stored procedures, triggers, views
…)
aadhayan academy of education
How MySQL stores data (by
default)
 A MySQL server can store several databases
 Databases are stored as directories
 Default is at /usr/local/mysql/var/
 Tables are stored as files inside each database
(directory)
 For each table, it has three files:
 table.FRM file containing information about the table
structure
 table.MYD file containing the row data
 table.MYI containing any indexes belonging with this
table, as well as some statistics about the table.aadhayan academy of education
Login
 mysql –h hostname –u username –p [password]
 Example
% mysql -u usrname -p
Enter password: passowrd
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 23 to server version: 3.23.41.
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
aadhayan academy of education
Create User and Database
 mysql>use mysql;
 Use database mysql, used by the system
 mysql>insert into user (Host, User,
Password) values (‘localhost’, ‘test1’,
password(‘pass1’));
 Create a new database user test1
 An alternative

GRANT USAGE ON *.* TO ‘test1’@’localhost‘
IDENTIFIED BY ‘pass1’;
aadhayan academy of education
Create User and Database (cont.)
 mysql>insert into db (Host, Db, User, Select_priv,
Insert_priv, Update_priv, Delete_priv, Create_priv,
Drop_priv) values (‘localhost’, ‘testdb’, ‘test1‘, ‘Y’, ‘Y’, ‘Y’,
‘Y’, ‘Y’, ‘Y’);
 Create a new database testdb for user test1
 mysql>flush privileges
 Reloads the privileges from the grant tables in the
database mysql
 An alternative
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE,
DROP ON testdb.* TO ‘test1’@’localhost’ IDENTIFIED
BY ‘pass1’;
aadhayan academy of education
What are the current databases at the server?
mysql> show databases;
+--------------+
| Database |
+--------------+
| mysql | mysql is a database (stores users’ password …) used by system.
| test |
+--------------+
Create a database (make a directory) whose name is MyDB
mysql> create database MyDB;
Select database to use
mysql> use MyDB;
Database changed
What tables are currently stored in the MyDB database?
mysql> show tables;
Empty set (0.00 sec)
Create Database
aadhayan academy of education
 CREATE TABLE Table_Name (column_specifications)
 Example
mysql> CREATE TABLE student
-> (
-> student_ID INT UNSIGNED NOT NULL,
-> name VARCHAR(20) NOT NULL,
-> major VARCHAR(50),
-> grade VARCHAR(5)
-> );
Query OK, 0 rows affected (0.00 sec)
Student_ID Name Major Grade
Create Table
aadhayan academy of education
Display Table Structure
mysql> show tables;
+--------------------+
| Tables_in_MyDB |
+--------------------+
| student |
+--------------------+
1 row in set (0.00 sec)
mysql> describe student;
+---------------+----------------------+------+------+----------+--------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------------+-------+-----+-----------+-------+
| student_ID | int(10) unsigned | | | 0 | |
| name | varchar(20) | | | | |
| major | varchar(50) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
+---------------+----------------------+-------+------+----------+-------+
4 rows in set (0.00 sec)
aadhayan academy of education
Modify Table Structure
 ALTER TABLE table_name Operations
mysql> alter table student add primary key (student_ID);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe student;
+---------------+--------------------- +-------+------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------------+-------+------+----------+-------+
| student_ID | int(10) unsigned | | PRI | 0 | |
| name | varchar(20) | | | | |
| major | varchar(10) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
+---------------+----------------------+-------+------+-----------+-------+
4 rows in set (0.00 sec)
aadhayan academy of education
Insert Record
 INSERT INTO table_name SET col_name1=value1,
col_name2=value2, col_name3=value3, …
 Example
mysql> INSERT INTO student SET student_ID=101, name='Shannon', major='BCB',
grade='A';
Query OK, 1 row affected (0.00 sec)
aadhayan academy of education
Student_ID Name Major Grade
101 Shannon BCB A
Retrieve Record
 SELECT what_columns
FROM table or tables
WHERE condition
 Example
mysql> SELECT major, grade FROM student
WHERE name='Shannon';
+-------+-------+
| major| grade|
+-------+-------+
| BCB | A |
+-------+-------+
1 row in set (0.00 sec)
mysql> SELECT * FROM student;
aadhayan academy of education
Student_ID Name Major Grade
101 Shannon BCB A
102 Mike BBMB A
103 Wang MCDB A
… … …
Update Record
 UPDATE table_name
SET which columns to change
WHERE condition
 Example
mysql> UPDATE student SET grade='B' WHERE name='Shannon';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM student WHERE name=‘Shannon’;
+------------+---------------+--------+--------+
| name | student_ID | major | grade |
+------------+---------------+--------+--------+
| Shannon | 101 | BCB | B |
+------------+---------------+--------+--------+
1 row in set (0.00 sec)
aadhayan academy of education
Delete Record
 DELETE FROM table_name WHERE condition
 Example
mysql> DELETE FROM student WHERE name='Shannon';
Query OK, 1 row affected (0.00 sec)
Mysql> DELETE FROM student;
Will delete ALL student records!
aadhayan academy of education
Drop Table
 DROP TABLE table_name
 Example
mysql> drop table student;
Query OK, 0 rows affected (0.00 sec)
 Logout MySQL
mysq> quit;
aadhayan academy of education
More Table Retrieval
 OR
mysql> select name from student where major = 'BCB' OR major = 'CS';
 COUNT (Count query results)
mysql> select count(name) from student where major = 'BCB' OR major = 'CS';
 ORDER BY (Sort query results)
mysql> select name from student where major = 'BCB' OR major = 'CS‘ ORDER
BY name;
mysql> select name from student where major = 'BCB' OR major = 'CS‘ ORDER
BY name DESC;
mysql> select * from student where major = 'BCB' OR major = 'CS‘ ORDER BY
student_id ASC, name DESC
 LIKE (Pattern matching)
mysql> select name from student where name LIKE "J%";
 DISTINCT (Remove duplicates)
mysql> select major from student;
mysql> select DISTINCT major from student;
aadhayan academy of education
Group By
 Cluster query results based on different groups
 Example
mysql> select major, count(*) from student GROUP BY major;
+---------+----------+
| major | count(*) |
+---------+----------+
| BBMB | 3 |
| BCB | 3 |
| Chem | 1 |
| CS | 5 |
| IG | 2 |
| Math | 2 |
| MCDB | 3 |
| Stat | 2 |
+---------+------------+
8 rows in set (0.00 sec)
aadhayan academy of education
NULL
 No Value
 Can not use the usual comparison operators (>, =, != …)
 Use IS or IS NOT operators to compare with
 Example
mysql> select name from student where project_ID = NULL;
Empty set (0.00 sec)
mysql> select name from student where project_ID IS NULL;
+-------+
| name|
+-------+
| Jerry |
+-------+
1 row in set (0.00 sec)
aadhayan academy of education
Table Join
 Retrieve information from multiple tables
 Example
 Which BCB students chose level-4 project?
mysql> select s.name from student s, project p
where s.project_ID = p.project_ID
and s.major='BCB' and p.level=4;
+------------+
| name |
+------------+
| Stephen |
+------------+
1 row in set (0.00 sec)
aadhayan academy of education
MySQL Optimization
 Index
 Index columns that you search for
 Example
mysql> alter table student add index (name);
Query OK, 22 rows affected (0.00 sec)
Records: 22 Duplicates: 0 Warnings: 0
mysql> describe student;
+---------------+----------------------+--------+-------+---------+---------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------------+--------+-------+---------+---------+
| student_ID | int(10) unsigned | | PRI | 0 | |
| name | varchar(20) | | MUL | | |
| major | varchar(10) | YES | | NULL | |
| project_ID | int(10) unsigned | YES | | NULL | |
+--------------+-----------------------+--------+-------+---------+---------+
4 rows in set (0.00 sec)
aadhayan academy of education
MySQL Optimization (cont.)
 EXPLAIN
 Find what is going on a slow query
 Example

mysql> EXPLAIN select * from student s, project p
where s.project_ID = p.project_ID order by p.level;
aadhayan academy of education

More Related Content

What's hot (19)

My sql1
My sql1My sql1
My sql1
 
MySQL lecture
MySQL lectureMySQL lecture
MySQL lecture
 
Mysql Introduction
Mysql IntroductionMysql Introduction
Mysql Introduction
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 
BITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema designBITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema design
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Introduction to my_sql
Introduction to my_sqlIntroduction to my_sql
Introduction to my_sql
 
MySQL
MySQLMySQL
MySQL
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
MYSQL
MYSQLMYSQL
MYSQL
 
Mysql Ppt
Mysql PptMysql Ppt
Mysql Ppt
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
 
Hbase
HbaseHbase
Hbase
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Introduction Mysql
Introduction Mysql Introduction Mysql
Introduction Mysql
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
 
Sql a practical introduction
Sql   a practical introductionSql   a practical introduction
Sql a practical introduction
 

Similar to My sql1

PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir Syed
 
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018teachersduniya.com
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 
Based on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docxBased on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docxJASS44
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinhwebhostingguy
 
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Ravikumar Nandigam
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manualMir Majid
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHPTaha Malampatti
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptxmebratu9
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part IIFirdaus Adib
 

Similar to My sql1 (20)

My SQL
My SQLMy SQL
My SQL
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
MySQL Record Operations
MySQL Record OperationsMySQL Record Operations
MySQL Record Operations
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
Sql
SqlSql
Sql
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
Based on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docxBased on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docx
 
Php modul-3
Php modul-3Php modul-3
Php modul-3
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
 
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manual
 
Mysql database
Mysql databaseMysql database
Mysql database
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptx
 
sql_data.pdf
sql_data.pdfsql_data.pdf
sql_data.pdf
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
 
Mysql all
Mysql allMysql all
Mysql all
 

Recently uploaded

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

My sql1

  • 1. Learning PHP-MySQL aadhayan academy of education By: Akash Gupta
  • 2. Course Contents aadhayan academy of education • Basics of Database • MySQL • PHP basics • HTML/Javascript/CSS basics • Creating a simple Registration form using html/php/javascript/css/mysql • More practicals… • Project
  • 3. Scopes of the Course aadhayan academy of education After completion of this course, you will: • Learn PHP and MySQL • Learn HTML, Javascript and CSS • Create a Webpage • Create a Industry-level project
  • 4. What is Database? aadhayan academy of education A database is a separate application that stores a collection of data. Each database has one or more distinct APIs for creating, accessing, managing, searching, and replicating the data it holds. Other kinds of data stores can be used, such as files on the file system or large hash tables in memory but data fetching and writing would not be so fast and easy with those type of systems. So now a days we use relational database management systems (RDBMS) to store and manager huge volume of data. This is called relational database because all the data is stored into different tables and relations are established using primary keys or other keys known as foreign keys. A Relational DataBase Management System (RDBMS) is a software that: • Enables you to implement a database with tables, columns, and indexes. • Guarantees the Referential Integrity between rows of various tables. • Updates the indexes automatically. • Interprets an SQL query and combines information from various tables.
  • 5. RDBMS Terminology aadhayan academy of education Before we proceed to explain MySQL database system, lets revise few definitions related to database. Database: A database is a collection of tables, with related data. Table: A table is a matrix with data. A table in a database looks like a simple spreadsheet. Column: One column (data element) contains data of one and the same kind, for example the column postcode. Row: A row (= tuple, entry or record) is a group of related data, for example the data of one subscription. Redundancy: Storing data twice, redundantly to make the system faster.
  • 6. aadhayan academy of education RDBMS Terminology cont. Primary Key: A primary key is unique. A key value can not occur twice in one table. With a key you can find at most one row. Foreign Key: A foreign key is the linking pin between two tables. Compound Key: A compound key (composite key) is a key that consists of multiple columns, because one column is not sufficiently unique. Index: An index in a database resembles an index at the back of a book. Referential Integrity: Referential Integrity makes sure that a foreign key value always points to an existing row.
  • 7. An example… aadhayan academy of education Student_ID Name Major Grade 101 Shannon BCB A 102 Mike BBMB A 103 Wang MCDB A … … …
  • 8. MySQL Introduction  MySQL is a fast, easy-to-use RDBMS used being used for many small and big businesses. MySQL is developed, marketed, and supported by MySQL AB, which is a Swedish company. MySQL is becoming so popular because of many good reasons.  MySQL is released under an open-source license. So you have nothing to pay to use it.  MySQL works on many operating systems and with many languages including PHP, PERL, C, C++, JAVA etc.  MySQL is very friendly to PHP, the most appreciated language for web development. aadhayan academy of education
  • 9. Basic MySQL Operations  Create table  Insert records  Load data  Retrieve records  Update records  Delete records  Modify table  Join table  Drop table  Optimize table  Count, Like, Order by, Group by  More advanced ones (sub-queries, stored procedures, triggers, views …) aadhayan academy of education
  • 10. How MySQL stores data (by default)  A MySQL server can store several databases  Databases are stored as directories  Default is at /usr/local/mysql/var/  Tables are stored as files inside each database (directory)  For each table, it has three files:  table.FRM file containing information about the table structure  table.MYD file containing the row data  table.MYI containing any indexes belonging with this table, as well as some statistics about the table.aadhayan academy of education
  • 11. Login  mysql –h hostname –u username –p [password]  Example % mysql -u usrname -p Enter password: passowrd Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 23 to server version: 3.23.41. Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> aadhayan academy of education
  • 12. Create User and Database  mysql>use mysql;  Use database mysql, used by the system  mysql>insert into user (Host, User, Password) values (‘localhost’, ‘test1’, password(‘pass1’));  Create a new database user test1  An alternative  GRANT USAGE ON *.* TO ‘test1’@’localhost‘ IDENTIFIED BY ‘pass1’; aadhayan academy of education
  • 13. Create User and Database (cont.)  mysql>insert into db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv) values (‘localhost’, ‘testdb’, ‘test1‘, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’);  Create a new database testdb for user test1  mysql>flush privileges  Reloads the privileges from the grant tables in the database mysql  An alternative  GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON testdb.* TO ‘test1’@’localhost’ IDENTIFIED BY ‘pass1’; aadhayan academy of education
  • 14. What are the current databases at the server? mysql> show databases; +--------------+ | Database | +--------------+ | mysql | mysql is a database (stores users’ password …) used by system. | test | +--------------+ Create a database (make a directory) whose name is MyDB mysql> create database MyDB; Select database to use mysql> use MyDB; Database changed What tables are currently stored in the MyDB database? mysql> show tables; Empty set (0.00 sec) Create Database aadhayan academy of education
  • 15.  CREATE TABLE Table_Name (column_specifications)  Example mysql> CREATE TABLE student -> ( -> student_ID INT UNSIGNED NOT NULL, -> name VARCHAR(20) NOT NULL, -> major VARCHAR(50), -> grade VARCHAR(5) -> ); Query OK, 0 rows affected (0.00 sec) Student_ID Name Major Grade Create Table aadhayan academy of education
  • 16. Display Table Structure mysql> show tables; +--------------------+ | Tables_in_MyDB | +--------------------+ | student | +--------------------+ 1 row in set (0.00 sec) mysql> describe student; +---------------+----------------------+------+------+----------+--------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+-------+-----+-----------+-------+ | student_ID | int(10) unsigned | | | 0 | | | name | varchar(20) | | | | | | major | varchar(50) | YES | | NULL | | | grade | varchar(5) | YES | | NULL | | +---------------+----------------------+-------+------+----------+-------+ 4 rows in set (0.00 sec) aadhayan academy of education
  • 17. Modify Table Structure  ALTER TABLE table_name Operations mysql> alter table student add primary key (student_ID); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe student; +---------------+--------------------- +-------+------+----------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+-------+------+----------+-------+ | student_ID | int(10) unsigned | | PRI | 0 | | | name | varchar(20) | | | | | | major | varchar(10) | YES | | NULL | | | grade | varchar(5) | YES | | NULL | | +---------------+----------------------+-------+------+-----------+-------+ 4 rows in set (0.00 sec) aadhayan academy of education
  • 18. Insert Record  INSERT INTO table_name SET col_name1=value1, col_name2=value2, col_name3=value3, …  Example mysql> INSERT INTO student SET student_ID=101, name='Shannon', major='BCB', grade='A'; Query OK, 1 row affected (0.00 sec) aadhayan academy of education Student_ID Name Major Grade 101 Shannon BCB A
  • 19. Retrieve Record  SELECT what_columns FROM table or tables WHERE condition  Example mysql> SELECT major, grade FROM student WHERE name='Shannon'; +-------+-------+ | major| grade| +-------+-------+ | BCB | A | +-------+-------+ 1 row in set (0.00 sec) mysql> SELECT * FROM student; aadhayan academy of education Student_ID Name Major Grade 101 Shannon BCB A 102 Mike BBMB A 103 Wang MCDB A … … …
  • 20. Update Record  UPDATE table_name SET which columns to change WHERE condition  Example mysql> UPDATE student SET grade='B' WHERE name='Shannon'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM student WHERE name=‘Shannon’; +------------+---------------+--------+--------+ | name | student_ID | major | grade | +------------+---------------+--------+--------+ | Shannon | 101 | BCB | B | +------------+---------------+--------+--------+ 1 row in set (0.00 sec) aadhayan academy of education
  • 21. Delete Record  DELETE FROM table_name WHERE condition  Example mysql> DELETE FROM student WHERE name='Shannon'; Query OK, 1 row affected (0.00 sec) Mysql> DELETE FROM student; Will delete ALL student records! aadhayan academy of education
  • 22. Drop Table  DROP TABLE table_name  Example mysql> drop table student; Query OK, 0 rows affected (0.00 sec)  Logout MySQL mysq> quit; aadhayan academy of education
  • 23. More Table Retrieval  OR mysql> select name from student where major = 'BCB' OR major = 'CS';  COUNT (Count query results) mysql> select count(name) from student where major = 'BCB' OR major = 'CS';  ORDER BY (Sort query results) mysql> select name from student where major = 'BCB' OR major = 'CS‘ ORDER BY name; mysql> select name from student where major = 'BCB' OR major = 'CS‘ ORDER BY name DESC; mysql> select * from student where major = 'BCB' OR major = 'CS‘ ORDER BY student_id ASC, name DESC  LIKE (Pattern matching) mysql> select name from student where name LIKE "J%";  DISTINCT (Remove duplicates) mysql> select major from student; mysql> select DISTINCT major from student; aadhayan academy of education
  • 24. Group By  Cluster query results based on different groups  Example mysql> select major, count(*) from student GROUP BY major; +---------+----------+ | major | count(*) | +---------+----------+ | BBMB | 3 | | BCB | 3 | | Chem | 1 | | CS | 5 | | IG | 2 | | Math | 2 | | MCDB | 3 | | Stat | 2 | +---------+------------+ 8 rows in set (0.00 sec) aadhayan academy of education
  • 25. NULL  No Value  Can not use the usual comparison operators (>, =, != …)  Use IS or IS NOT operators to compare with  Example mysql> select name from student where project_ID = NULL; Empty set (0.00 sec) mysql> select name from student where project_ID IS NULL; +-------+ | name| +-------+ | Jerry | +-------+ 1 row in set (0.00 sec) aadhayan academy of education
  • 26. Table Join  Retrieve information from multiple tables  Example  Which BCB students chose level-4 project? mysql> select s.name from student s, project p where s.project_ID = p.project_ID and s.major='BCB' and p.level=4; +------------+ | name | +------------+ | Stephen | +------------+ 1 row in set (0.00 sec) aadhayan academy of education
  • 27. MySQL Optimization  Index  Index columns that you search for  Example mysql> alter table student add index (name); Query OK, 22 rows affected (0.00 sec) Records: 22 Duplicates: 0 Warnings: 0 mysql> describe student; +---------------+----------------------+--------+-------+---------+---------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+--------+-------+---------+---------+ | student_ID | int(10) unsigned | | PRI | 0 | | | name | varchar(20) | | MUL | | | | major | varchar(10) | YES | | NULL | | | project_ID | int(10) unsigned | YES | | NULL | | +--------------+-----------------------+--------+-------+---------+---------+ 4 rows in set (0.00 sec) aadhayan academy of education
  • 28. MySQL Optimization (cont.)  EXPLAIN  Find what is going on a slow query  Example  mysql> EXPLAIN select * from student s, project p where s.project_ID = p.project_ID order by p.level; aadhayan academy of education