SlideShare a Scribd company logo
1 of 32
Introduction to PHPIntroduction to PHP
MySQL Joins and SQLMySQL Joins and SQL
FunctionsFunctions
MySQL/PHP WorkshopMySQL/PHP Workshop
• 2 MySQL lectures
• 2 PHP lectures
• Each lecture builds on concepts taught and learned in the previous
lectures.
• The first two lectures discuss the concept of a relational database
such as MySQL and show you how to manipulate the data stored in
the database from the command line. It is essential to learn this first
because PHP makes use of the language of the database.
• The third and fourth lectures will introduce you to PHP, a server-side
scripting language that allows you to interact with the MySQL
database from a web browser and create fancy web pages to
display the data. PHP is the go-between that fetches the data from
the MySQL database and then spits it out dynamically as the nicely
formatted HTML page that the browser expects.
Introduction to MySQLIntroduction to MySQL
• Relational databases
• Database design
• SQL
o Creating databases
o Creating tables
o Selecting from, deleting, and updating tables
• Exercises
• You should have
o Class notes
o Exercise handout
o MySQL Pocket Reference
First Name Last Name Phone
Nadia Li 2687
Madhu Charu 7856
Ajuma Kinsaka 4489
Wade Randal 5257
Helen Clark 2147
Employees
Relational DatabasesRelational Databases
• A database is a collection of tables
• Columns define attributes of the data
o All data in a column must have the same data
type
• A record is stored in a row
table name
column
row
Use a Relational DatabaseUse a Relational Database
When…When…
• You have a very large dataset
• There is redundant data
o Wastes disk space
o Increases errors
• Information must be updated in multiple locations
• Security is important
o Different users can be granted different permissions
• Strict enforcement of data types is important
Spreadsheet ExampleSpreadsheet Example
Title Author Borrower Phone
A House for Mr. Biswas VS Naipaul Sarah 646.555.1234
Midnight's Children Salman Rushdie
On the Road Jack Kerouac
Spreadsheet ExampleSpreadsheet Example
Title Author Borrower Phone
A House for Mr. Biswas VS Naipaul Sarah 646.555.1234
Midnight's Children Salman Rushdie
On the Road Jack Kerouac
Data is inconsistent!
Now imagine you are designing the New York Public
Library database which has tens of million books and
well over a million cardholders.
One Flew Over the Cuckoo's Nest Ken Kesey Sarah 646.555.1244
Sula Toni Morrison
Villette Charlotte Bronte Jim 646.555.4586
Database DesignDatabase Design
Entity Relationship Design
Entity (“thing”, “object”) Table
Attributes (describe entity) Columns
Entity Instance Row
Relationships between entities preserved in relationships
between tables.
If you are interested in learning more formal design
methods look up “normalization” and/or “third normal
form”.
Our dataOur dataEnsembl Gene ID Symbol /
Name
Chromo
some
Start
Position
(bp)
End
Position
(bp)
LocusLink
ID
Taxonomy
ID
Common
Name
Species
ENSG00000186891.3 TNFRSF18 1 1044947 1048147 8784 9606 human Homo sapiens
ENSG00000078808.4 CAB45 1 1058370 1073469 51150 9606 human Homo sapiens
ENSG00000176022.1 B3GALT6 1 1073703 1076476 126792 9606 human Homo sapiens
ENSG00000160087.5 UBE2J2 1 1095352 1115292 118424 9606 human Homo sapiens
ENSG00000162572.4 SCNN1D 1 1123634 1133467 6339 9606 human Homo sapiens
ENSG00000162576.4 MGC3047 1 1194130 1199973 84308 9606 human Homo sapiens
ENSG00000175756.3 AKIP 1 1215168 1216641 54998 9606 human Homo sapiens
ENSG00000131586.2 MRPL20 1 1288703 1294063 55052 9606 human Homo sapiens
ENSG00000179403.2 WARP 1 1322311 1327547 64856 9606 human Homo sapiens
ENSG00000160072.5 ATAD3B 1 1358611 1396091 83858 9606 human Homo sapiens
ENSG00000008128.5 CDC2L2 1 1582617 1604060 985 9606 human Homo sapiens
ENSG00000169911.4 SLC35E2 1 1611978 1625728 9906 9606 human Homo sapiens
ENSG00000008130.3 FLJ13052 1 1630975 1659805 65220 9606 human Homo sapiens
ENSG00000078369.3 GNB1 1 1665027 1770792 2782 9606 human Homo sapiens
ENSMUSG00000041954.1 TNFRSF18 4 154139702 154142251 21936 10090 mouse Mus musculus
ENSMUSG00000023286.1 UBE2J2 4 154057210 1540722964 140499 10090 mouse Mus musculus
Our tablesOur tables
How do we know which organism a gene belongs to?
Do we have unique identifiers?
Can the organism have more than one gene?
Can the gene have more than one organism?
Database Design CaveatDatabase Design Caveat
• Sometimes design is “sacrificed” for speed.
Data TypesData Types
• float
• integer
• tinyint
• varchar(size)
o stores strings
o size can be between 0 - 255, inclusive
• datetime
• + more What data types should our attributes (columns) be?
Complete DesignComplete Design Gene
Column Data Type
gene_id integer
ensembl_gene_id varchar(50)
organism_id integer
name varchar(35)
locuslink varchar(10)
chromosome tinyint
chromo_start integer
chromo_end integer
description varchar(255)
Organism
Column Data Type
organism_id integer
taxonomy_id integer
common_name varchar(35)
species varchar(35)
Database name: ensmartdb
Connecting to MySQL from the Command LineConnecting to MySQL from the Command Line
mysql -uusername -p
Example:
>mysql -uroot
To EXIT MySQL:
EXIT;
Basic SQL CommandsBasic SQL Commands
• SQL statements end with a semicolon
• View databases
SHOW DATABASES;
Importing a DatabaseImporting a Database
• Creating a database
CREATE DATABASE trii;
• From the command line:
mysql -uusername -ppassword databasename <
filename.sql
• Example:
o mysql -uroot trii < trii.sql
Basic SQL CommandsBasic SQL Commands
• Use database databasename
USE databasename;
• Display all tables in a database
SHOW TABLES;
Create TableCreate Table
CREATE TABLE organism (
organism_id INTEGER NOT NULL AUTO_INCREMENT,
taxonomy_id INTEGER NOT NULL,
common_name VARCHAR(35) NOT NULL,
species VARCHAR(35) NOT NULL,
PRIMARY KEY (organism_id),
UNIQUE (taxonomy_id)
);
database name
column
names
View column details for a tableView column details for a table
DESC tablename;
Selecting all dataSelecting all data
SELECT * FROM tablename;
Select only the columnsSelect only the columns
you needyou need (it will be faster)(it will be faster)
SELECT common_name, species
FROM organism;
Limiting your dataLimiting your data
• Get the species name for a specific organism (you
have the id)
SELECT species
FROM organism
WHERE organism_id=1;
How do we select all the gene names for chromosome 1?
InsertInsert
• Inserting a gene
INSERT INTO gene
(ensembl_gene_id,
organism_id,
name,
chromosome,
chromo_start,
chromo_end) VALUES (‘MY_NEW_GENE’,
1, ‘MY GENE’, 1, 12345, 67890);
• Get the id of the gene:
SELECT gene_id FROM gene WHERE name='MY GENE';
Delete/UpdateDelete/Update
• Deleting a gene
DELETE FROM gene WHERE gene_id=19;
• Updating a gene
UPDATE gene SET name=‘NEW NAME’
WHERE name=‘AKIP’;
Table JoinsTable Joins
• Sometimes you want data from more than one
table. To do this we join the tables. The result is a
new (temporary) table.
Cross JoinCross Join
• SELECT gene.name, organism.species
FROM gene, organism;
Note: There are only
two records in the
gene table with the
name “TNFRSF18”.
One is a mouse gene
and the other is a
human gene. What do
you think happened?
Cross Join (Continued)Cross Join (Continued)
Each row of the gene table was joined with
every row in the organism table.
Cross Join (Continued)Cross Join (Continued)
• We want to use the organism id to match a gene
record with the correct organism record so that we
get:
Remember there
are two gene
records with the
name “TNFRSF18”.
Cross Join (Continued)Cross Join (Continued)
SELECT gene.name, organism.species
FROM gene, organism
WHERE gene.organism_id=organism.organism_id;
Notice that we have 18
rows and that there are
18 rows in the gene
table.
ThankThank You !!!You !!!
For More Information click below link:
Follow Us on:
http://vibranttechnologies.co.in/php-classes-in-mumbai

More Related Content

Similar to PHP - Introduction to PHP MySQL Joins and SQL Functions

Creating an Open Source Genealogical Search Engine with Apache Solr
Creating an Open Source Genealogical Search Engine with Apache SolrCreating an Open Source Genealogical Search Engine with Apache Solr
Creating an Open Source Genealogical Search Engine with Apache SolrBrooke Ganz
 
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)barcelonajug
 
AZMS PRESENTATION.pptx
AZMS PRESENTATION.pptxAZMS PRESENTATION.pptx
AZMS PRESENTATION.pptxSonuShaw16
 
Data Management for Quantitative Biology - Database systems, May 7, 2015, Dr....
Data Management for Quantitative Biology - Database systems, May 7, 2015, Dr....Data Management for Quantitative Biology - Database systems, May 7, 2015, Dr....
Data Management for Quantitative Biology - Database systems, May 7, 2015, Dr....QBiC_Tue
 
Case study of Rujhaan.com (A social news app )
Case study of Rujhaan.com (A social news app )Case study of Rujhaan.com (A social news app )
Case study of Rujhaan.com (A social news app )Rahul Jain
 
2019 03 05_biological_databases_part5_v_upload
2019 03 05_biological_databases_part5_v_upload2019 03 05_biological_databases_part5_v_upload
2019 03 05_biological_databases_part5_v_uploadProf. Wim Van Criekinge
 
Elasticsearch in Production
Elasticsearch in ProductionElasticsearch in Production
Elasticsearch in Productionfoundsearch
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxPythian
 
The Right Data for the Right Job
The Right Data for the Right JobThe Right Data for the Right Job
The Right Data for the Right JobEmily Curtin
 
YQL: Select * from Internet
YQL: Select * from InternetYQL: Select * from Internet
YQL: Select * from Internetdrgath
 
What You Need To Know About The Top Database Trends
What You Need To Know About The Top Database TrendsWhat You Need To Know About The Top Database Trends
What You Need To Know About The Top Database TrendsDell World
 
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail ScienceSQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail ScienceUniversity of Washington
 
Future Architectures for genomics
Future Architectures for genomicsFuture Architectures for genomics
Future Architectures for genomicsGuy Coates
 
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...Marco Gralike
 
Elasticsearch - basics and beyond
Elasticsearch - basics and beyondElasticsearch - basics and beyond
Elasticsearch - basics and beyondErnesto Reig
 
Semi-automated Exploration and Extraction of Data in Scientific Tables
Semi-automated Exploration and Extraction of Data in Scientific TablesSemi-automated Exploration and Extraction of Data in Scientific Tables
Semi-automated Exploration and Extraction of Data in Scientific TablesElsevier
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptxnatesanp1234
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at nightMichael Yarichuk
 

Similar to PHP - Introduction to PHP MySQL Joins and SQL Functions (20)

Creating an Open Source Genealogical Search Engine with Apache Solr
Creating an Open Source Genealogical Search Engine with Apache SolrCreating an Open Source Genealogical Search Engine with Apache Solr
Creating an Open Source Genealogical Search Engine with Apache Solr
 
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
 
AZMS PRESENTATION.pptx
AZMS PRESENTATION.pptxAZMS PRESENTATION.pptx
AZMS PRESENTATION.pptx
 
Data Management for Quantitative Biology - Database systems, May 7, 2015, Dr....
Data Management for Quantitative Biology - Database systems, May 7, 2015, Dr....Data Management for Quantitative Biology - Database systems, May 7, 2015, Dr....
Data Management for Quantitative Biology - Database systems, May 7, 2015, Dr....
 
Case study of Rujhaan.com (A social news app )
Case study of Rujhaan.com (A social news app )Case study of Rujhaan.com (A social news app )
Case study of Rujhaan.com (A social news app )
 
2019 03 05_biological_databases_part5_v_upload
2019 03 05_biological_databases_part5_v_upload2019 03 05_biological_databases_part5_v_upload
2019 03 05_biological_databases_part5_v_upload
 
Elasticsearch in Production
Elasticsearch in ProductionElasticsearch in Production
Elasticsearch in Production
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
 
The Right Data for the Right Job
The Right Data for the Right JobThe Right Data for the Right Job
The Right Data for the Right Job
 
YQL: Select * from Internet
YQL: Select * from InternetYQL: Select * from Internet
YQL: Select * from Internet
 
What You Need To Know About The Top Database Trends
What You Need To Know About The Top Database TrendsWhat You Need To Know About The Top Database Trends
What You Need To Know About The Top Database Trends
 
Sql material
Sql materialSql material
Sql material
 
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail ScienceSQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
SQL is Dead; Long Live SQL: Lightweight Query Services for Long Tail Science
 
Future Architectures for genomics
Future Architectures for genomicsFuture Architectures for genomics
Future Architectures for genomics
 
PHP - Introduction to Advanced SQL
PHP - Introduction to Advanced SQLPHP - Introduction to Advanced SQL
PHP - Introduction to Advanced SQL
 
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
 
Elasticsearch - basics and beyond
Elasticsearch - basics and beyondElasticsearch - basics and beyond
Elasticsearch - basics and beyond
 
Semi-automated Exploration and Extraction of Data in Scientific Tables
Semi-automated Exploration and Extraction of Data in Scientific TablesSemi-automated Exploration and Extraction of Data in Scientific Tables
Semi-automated Exploration and Extraction of Data in Scientific Tables
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptx
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at night
 

More from Vibrant Technologies & Computers

Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Vibrant Technologies & Computers
 

More from Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
 

Recently uploaded

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Recently uploaded (20)

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

PHP - Introduction to PHP MySQL Joins and SQL Functions

  • 1.
  • 2. Introduction to PHPIntroduction to PHP MySQL Joins and SQLMySQL Joins and SQL FunctionsFunctions
  • 3. MySQL/PHP WorkshopMySQL/PHP Workshop • 2 MySQL lectures • 2 PHP lectures • Each lecture builds on concepts taught and learned in the previous lectures. • The first two lectures discuss the concept of a relational database such as MySQL and show you how to manipulate the data stored in the database from the command line. It is essential to learn this first because PHP makes use of the language of the database. • The third and fourth lectures will introduce you to PHP, a server-side scripting language that allows you to interact with the MySQL database from a web browser and create fancy web pages to display the data. PHP is the go-between that fetches the data from the MySQL database and then spits it out dynamically as the nicely formatted HTML page that the browser expects.
  • 4. Introduction to MySQLIntroduction to MySQL • Relational databases • Database design • SQL o Creating databases o Creating tables o Selecting from, deleting, and updating tables • Exercises • You should have o Class notes o Exercise handout o MySQL Pocket Reference
  • 5. First Name Last Name Phone Nadia Li 2687 Madhu Charu 7856 Ajuma Kinsaka 4489 Wade Randal 5257 Helen Clark 2147 Employees Relational DatabasesRelational Databases • A database is a collection of tables • Columns define attributes of the data o All data in a column must have the same data type • A record is stored in a row table name column row
  • 6. Use a Relational DatabaseUse a Relational Database When…When… • You have a very large dataset • There is redundant data o Wastes disk space o Increases errors • Information must be updated in multiple locations • Security is important o Different users can be granted different permissions • Strict enforcement of data types is important
  • 7. Spreadsheet ExampleSpreadsheet Example Title Author Borrower Phone A House for Mr. Biswas VS Naipaul Sarah 646.555.1234 Midnight's Children Salman Rushdie On the Road Jack Kerouac
  • 8. Spreadsheet ExampleSpreadsheet Example Title Author Borrower Phone A House for Mr. Biswas VS Naipaul Sarah 646.555.1234 Midnight's Children Salman Rushdie On the Road Jack Kerouac Data is inconsistent! Now imagine you are designing the New York Public Library database which has tens of million books and well over a million cardholders. One Flew Over the Cuckoo's Nest Ken Kesey Sarah 646.555.1244 Sula Toni Morrison Villette Charlotte Bronte Jim 646.555.4586
  • 9. Database DesignDatabase Design Entity Relationship Design Entity (“thing”, “object”) Table Attributes (describe entity) Columns Entity Instance Row Relationships between entities preserved in relationships between tables. If you are interested in learning more formal design methods look up “normalization” and/or “third normal form”.
  • 10. Our dataOur dataEnsembl Gene ID Symbol / Name Chromo some Start Position (bp) End Position (bp) LocusLink ID Taxonomy ID Common Name Species ENSG00000186891.3 TNFRSF18 1 1044947 1048147 8784 9606 human Homo sapiens ENSG00000078808.4 CAB45 1 1058370 1073469 51150 9606 human Homo sapiens ENSG00000176022.1 B3GALT6 1 1073703 1076476 126792 9606 human Homo sapiens ENSG00000160087.5 UBE2J2 1 1095352 1115292 118424 9606 human Homo sapiens ENSG00000162572.4 SCNN1D 1 1123634 1133467 6339 9606 human Homo sapiens ENSG00000162576.4 MGC3047 1 1194130 1199973 84308 9606 human Homo sapiens ENSG00000175756.3 AKIP 1 1215168 1216641 54998 9606 human Homo sapiens ENSG00000131586.2 MRPL20 1 1288703 1294063 55052 9606 human Homo sapiens ENSG00000179403.2 WARP 1 1322311 1327547 64856 9606 human Homo sapiens ENSG00000160072.5 ATAD3B 1 1358611 1396091 83858 9606 human Homo sapiens ENSG00000008128.5 CDC2L2 1 1582617 1604060 985 9606 human Homo sapiens ENSG00000169911.4 SLC35E2 1 1611978 1625728 9906 9606 human Homo sapiens ENSG00000008130.3 FLJ13052 1 1630975 1659805 65220 9606 human Homo sapiens ENSG00000078369.3 GNB1 1 1665027 1770792 2782 9606 human Homo sapiens ENSMUSG00000041954.1 TNFRSF18 4 154139702 154142251 21936 10090 mouse Mus musculus ENSMUSG00000023286.1 UBE2J2 4 154057210 1540722964 140499 10090 mouse Mus musculus
  • 11. Our tablesOur tables How do we know which organism a gene belongs to? Do we have unique identifiers? Can the organism have more than one gene? Can the gene have more than one organism?
  • 12. Database Design CaveatDatabase Design Caveat • Sometimes design is “sacrificed” for speed.
  • 13. Data TypesData Types • float • integer • tinyint • varchar(size) o stores strings o size can be between 0 - 255, inclusive • datetime • + more What data types should our attributes (columns) be?
  • 14. Complete DesignComplete Design Gene Column Data Type gene_id integer ensembl_gene_id varchar(50) organism_id integer name varchar(35) locuslink varchar(10) chromosome tinyint chromo_start integer chromo_end integer description varchar(255) Organism Column Data Type organism_id integer taxonomy_id integer common_name varchar(35) species varchar(35) Database name: ensmartdb
  • 15. Connecting to MySQL from the Command LineConnecting to MySQL from the Command Line mysql -uusername -p Example: >mysql -uroot To EXIT MySQL: EXIT;
  • 16. Basic SQL CommandsBasic SQL Commands • SQL statements end with a semicolon • View databases SHOW DATABASES;
  • 17. Importing a DatabaseImporting a Database • Creating a database CREATE DATABASE trii; • From the command line: mysql -uusername -ppassword databasename < filename.sql • Example: o mysql -uroot trii < trii.sql
  • 18. Basic SQL CommandsBasic SQL Commands • Use database databasename USE databasename; • Display all tables in a database SHOW TABLES;
  • 19. Create TableCreate Table CREATE TABLE organism ( organism_id INTEGER NOT NULL AUTO_INCREMENT, taxonomy_id INTEGER NOT NULL, common_name VARCHAR(35) NOT NULL, species VARCHAR(35) NOT NULL, PRIMARY KEY (organism_id), UNIQUE (taxonomy_id) ); database name column names
  • 20. View column details for a tableView column details for a table DESC tablename;
  • 21. Selecting all dataSelecting all data SELECT * FROM tablename;
  • 22. Select only the columnsSelect only the columns you needyou need (it will be faster)(it will be faster) SELECT common_name, species FROM organism;
  • 23. Limiting your dataLimiting your data • Get the species name for a specific organism (you have the id) SELECT species FROM organism WHERE organism_id=1; How do we select all the gene names for chromosome 1?
  • 24. InsertInsert • Inserting a gene INSERT INTO gene (ensembl_gene_id, organism_id, name, chromosome, chromo_start, chromo_end) VALUES (‘MY_NEW_GENE’, 1, ‘MY GENE’, 1, 12345, 67890); • Get the id of the gene: SELECT gene_id FROM gene WHERE name='MY GENE';
  • 25. Delete/UpdateDelete/Update • Deleting a gene DELETE FROM gene WHERE gene_id=19; • Updating a gene UPDATE gene SET name=‘NEW NAME’ WHERE name=‘AKIP’;
  • 26. Table JoinsTable Joins • Sometimes you want data from more than one table. To do this we join the tables. The result is a new (temporary) table.
  • 27. Cross JoinCross Join • SELECT gene.name, organism.species FROM gene, organism; Note: There are only two records in the gene table with the name “TNFRSF18”. One is a mouse gene and the other is a human gene. What do you think happened?
  • 28. Cross Join (Continued)Cross Join (Continued) Each row of the gene table was joined with every row in the organism table.
  • 29. Cross Join (Continued)Cross Join (Continued) • We want to use the organism id to match a gene record with the correct organism record so that we get: Remember there are two gene records with the name “TNFRSF18”.
  • 30. Cross Join (Continued)Cross Join (Continued) SELECT gene.name, organism.species FROM gene, organism WHERE gene.organism_id=organism.organism_id;
  • 31. Notice that we have 18 rows and that there are 18 rows in the gene table.
  • 32. ThankThank You !!!You !!! For More Information click below link: Follow Us on: http://vibranttechnologies.co.in/php-classes-in-mumbai

Editor's Notes

  1. Answers: Gene, Organism Yes, the species information is repeated If we add another species attribute, for example “genus”, we will have to be careful to update all the records. We don’t have one record which contains the attributes for species “human”, so when we add the genus for the human species we must add it to every human record.
  2. Answers: We must store an organism id with the gene information. Yes, the Ensembl_Gene_ID uniquely identifies a gene, and the Taxonomy_ID uniquely identifies an organism. Each organism has many genes. In our database each gene belongs to only one organism.
  3. For example, sometimes it is faster to have one huge table with redundant data than to have no redundancy and tables that must be joined. If this is the case, and speed is the top priority, design has not really been sacrificed by introducing redundancy since the design meets the need of your situation.
  4. See “MySQL Pocket Reference” for a complete list of data types.
  5. Create Trii Database Download http://www.trii.org/courses/introtomysql/trii.sql Save as trii.sql in the training home directory. At the command prompt (NOT in MySQL): mysql -uroot &amp;lt; trii.sql Run MySQL again mysql -uroot