Download - PHP mysql Introduction database
![Page 1: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/1.jpg)
Introduction To
Databases
![Page 2: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/2.jpg)
Basicprogramming experience
![Page 3: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/3.jpg)
WHAT ARE Databases?
![Page 4: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/4.jpg)
![Page 5: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/5.jpg)
![Page 6: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/6.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 7: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/7.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 8: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/8.jpg)
![Page 9: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/9.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 10: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/10.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 11: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/11.jpg)
![Page 12: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/12.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 13: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/13.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 14: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/14.jpg)
![Page 15: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/15.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 16: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/16.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 17: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/17.jpg)
![Page 18: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/18.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 19: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/19.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 20: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/20.jpg)
![Page 21: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/21.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 22: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/22.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 23: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/23.jpg)
![Page 24: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/24.jpg)
size
ease of updating
accuracy
security
redundancy
importance
![Page 25: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/25.jpg)
Database Management Systems(DBMS)
Oracle
SQL Server
MySQL
PostgreSQL
MongoDB
…
![Page 26: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/26.jpg)
DBMS
Software
database database
Other DBMS
![Page 27: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/27.jpg)
Relational database features
![Page 28: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/28.jpg)
table table
table
database
![Page 29: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/29.jpg)
table
columns
rows
![Page 30: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/30.jpg)
![Page 31: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/31.jpg)
table
columns
rows
![Page 32: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/32.jpg)
FirstName LastName HireDate Grade Salary City
table
columns
rows
![Page 33: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/33.jpg)
FirstName(text)
LastName (text)
HireDate (Date)
Grade (numeric)
Salary (currency)
City (text)
table
columns
rows
![Page 34: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/34.jpg)
FirstName(text)
LastName (text)
HireDate (Date)
Grade (numeric)
Salary (currency)
City (text)
James Black 03/10/2014 7 15000 HYD
table
columns
rows
![Page 35: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/35.jpg)
FirstName(text)
LastName (text)
HireDate (Date)
Grade (numeric)
Salary (currency)
City (text)
FirstName LastName 03/10/2013 8 15000 CA
James Black 03/10/2014 7 15000 HYD
FirstName LastName 03/10/2013 8 15000 CA
FirstName LastName 03/10/2013 8 15000 CA
FirstName LastName 03/10/2013 8 15000 CA
table
columns
rows
![Page 36: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/36.jpg)
WHAT IS A DATABASE?•A database is a bunch of information
–It is a structured collection of information
–It contains basic objects, called records or entries
–The records contain fields, which contain defined types of
data, somehow related to that record.
–A university database would contain for example all kinds
of students as records, and students properties (ID,name,
etc) as fields.
![Page 37: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/37.jpg)
WHAT IS A DATABASE?•A database is searchable
–It contains an index (table of content, catalog)
•It is updated regularly
–New data goes in
•Obsolete, old data goes out
–It is cross referenced To other databases
![Page 38: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/38.jpg)
WHY DATABASES?•The main purpose of databases is not only to collect and
organize data, but to allow advanced data retrieval and
analysis
•A database query is a method to retrieve information from the
database
•The organization of records into fields allows us to use
queries on fields.
![Page 39: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/39.jpg)
DATABASES ON THE INTERNET
USER
DATABASE
SERVER
WEBSERVERS
![Page 40: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/40.jpg)
Introduction to MySQL
![Page 41: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/41.jpg)
ROAD MAP•Introduction to MySQL
•Connecting and Disconnecting
•Entering Basic Queries
•Creating and Using a Database
![Page 42: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/42.jpg)
MySQL•MySQL is a very popular, open source database.
•Officially pronounced “my Ess Que Ell” (not my sequel).
•Handles very large databases; very fast performance.
•Why are we using MySQL?
–Free (much cheaper than Oracle!)
–Each student can install MySQL locally.
–Easy to use Shell for creating tables, querying tables, etc.
–Easy to use with PHP
![Page 43: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/43.jpg)
CONNECTING TO MYSQL•MySQL provides an interactive shell for creating tables,
inserting data, etc.
•On Windows, just go to c:\mysql\bin, and type:
•Mysql –u root -p
•Or, click on the Windows icon
![Page 44: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/44.jpg)
SAMPLE SESSION For example:
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 241 to server version: 3.23.49
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
To exit the MySQL Shell, just type QUIT or EXIT:
mysql> QUIT
mysql> exit
![Page 45: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/45.jpg)
BASIC QUERIES Once logged in, you can try some simple queries.
For example:
mysql> SELECT VERSION(), CURRENT_DATE;
+-----------+--------------+
| VERSION() | CURRENT_DATE |
+-----------+--------------+
| 3.23.49 | 2002-05-26 |
+-----------+--------------+
1 row in set (0.00 sec)
Note that most MySQL commands end with a semicolon (;)
MySQL returns the total number of rows found, and the total time to execute the query.
![Page 46: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/46.jpg)
BASIC QUERIES Keywords may be entered in any lettercase.
The following queries are equivalent:
mysql> SELECT VERSION(), CURRENT_DATE;
mysql> select version(), current_date;
mysql> SeLeCt vErSiOn(), current_DATE;
![Page 47: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/47.jpg)
BASIC QUERIES Here's another query. It demonstrates that you
can use mysql as a simple calculator:
mysql> SELECT SIN(PI()/4), (4+1)*5;
+-------------+---------+
| SIN(PI()/4) | (4+1)*5 |
+-------------+---------+
| 0.707107 | 25 |
+-------------+---------+
![Page 48: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/48.jpg)
BASIC QUERIES You can also enter multiple statements on a
single line. Just end each one with a semicolon:
mysql> SELECT VERSION(); SELECT NOW();
+--------------+
| VERSION() |
+--------------+
| 3.22.20a-log |
+--------------+
+---------------------+
| NOW() |
+---------------------+
| 2004 00:15:33 |
+---------------------+
![Page 49: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/49.jpg)
MULTI-LINE COMMANDS mysql determines where your statement ends by
looking for the terminating semicolon, not by looking for the end of the input line.
Here's a simple multiple-line statement:
mysql> SELECT
-> USER()
-> ,
-> CURRENT_DATE;
+--------------------+--------------+
| USER() | CURRENT_DATE |
+--------------------+--------------+
| joesmith@localhost | 1999-03-18 |
+--------------------+--------------+
![Page 50: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/50.jpg)
CANCELING A COMMAND If you decide you don't want to execute a
command that you are in the process of entering, cancel it by typing \c
mysql> SELECT
-> USER()
-> \c
mysql>
![Page 51: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/51.jpg)
USING A DATABASE To get started on your own database, first check
which databases currently exist.
Use the SHOW statement to find out which databases currently exist on the server:
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.01 sec)
![Page 52: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/52.jpg)
USING A DATABASE To create a new database, issue the “create
database” command:
mysql> create database webdb;
To the select a database, issue the “use” command:
mysql> use webdb;
![Page 53: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/53.jpg)
CREATING A TABLE Let’s create a table for storing pets.
Table: pets name: VARCHAR(20)
owner: VARCHAR(20)
species: VARCHAR(20)
gender: CHAR(1)
birth: DATE
date: DATE
![Page 54: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/54.jpg)
CREATING A TABLE To create a table, use the CREATE TABLE
command:
mysql> CREATE TABLE pet (
-> name VARCHAR(20),
-> owner VARCHAR(20),
-> species VARCHAR(20),
-> gender CHAR(1),
-> birth DATE, death DATE);
Query OK, 0 rows affected (0.04 sec)
![Page 55: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/55.jpg)
SHOWING TABLES
To verify that the table has been created:
mysql> show tables;
+------------------+
| Tables_in_test |
+------------------+
| pet |
+------------------+
1 row in set (0.01 sec)
![Page 56: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/56.jpg)
DESCRIBING TABLES To view a table structure, use the DESCRIBE
command:
mysql> describe pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.02 sec)
![Page 57: PHP mysql Introduction database](https://reader034.vdocuments.site/reader034/viewer/2022042607/55a614501a28abee328b458f/html5/thumbnails/57.jpg)
DELETING A TABLE
To delete an entire table, use the DROP
TABLE command:
mysql> drop table pet;
Query OK, 0 rows affected (0.02 sec)