Download presentation
Presentation is loading. Please wait.
1
PHP and MySQL
2
What is the Relationship between PHP and MySQL?
PHP has the ability to connect to and manipulate databases. The most popular database system that is used with PHP is called MySQL. MySQL is a free database system and is supported by most servers.
3
MySQL - Fundamental Functions
Organize data – reduce or eliminate redundancy Retrieve data – query/search/select Sort data Update data Output – link to other software
4
MySQL Client/Server architecture Limited User Interface (PHPMyAdmin)
MySQL is cross platform, multi user access Accessible to more users thru the web, client program or other admin tools to access database (via authentication) Can be integrated with Web Server (web programming languages) Data available remotely Free, open-source
5
Data Types Data Type Definition Text 0-255 characters Memo
Number Integer, long integer, single, double Date/Time Dates, times, or both at once AutoNumber Automatically incremented as records are added OLE object Image, sound files Hyperlink Link to an internet resource
6
Practice 1: Determine Data Types
Books Authors TITLE PUBLISHER_id ISBN QTY. Id ISBN Author Publishers PUBLISHER_id PUBLISHER
7
Practice 1: Data Types - Solution
Books Authors TITLE Text (255) PUBLISHER_id Number (integer) ISBN Text(10) QTY. Number(integer) Id Number(integer) ISBN Text(10) Author text(255) Publishers PUBLISHER_id integer PUBLISHER text(255)
8
Practice 2: Determine Data Types Personnel Institutions Positions
Pers_id Last First M.I. Institution_id Institutions Institution_id Institution Sector Positions id pers_id position
9
Practice 2: Solution Data Types Personnel Institutions Positions
Pers_id Number (integer) Last Text(255) First M.I. Text(1) Institution_id Institutions Institution_id Number(integer) Institution text(255) Sector Text(25) Positions id Number(integer) pers_id position Text(200)
10
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 …)
11
SELECT SELECT is used to select data from a database
The result is stored in a result table, called the result-set SQL is not case sensitive SELECT syntax SELECT column_name(s) FROM table_name; SELECT * FROM table_name;
12
SELECT Persons Table P_Id LastName FirstName Address City 1 Hansen Ola
Timoteivn 10 Sandnes 2 Svendson Tove Borgvn 23 3 Pettersen Kari Storgt 20 Stavanger SELECT LastName, FirstName FROM Persons; SELECT *FROM Persons;
13
WHERE clause SELECT column_name(s) FROM table_name
WHERE column_name operator value; SELECT * FROM persons WHERE city=‘Sandnes’;
14
WHERE Clause Text values should be quoted by single quotes or double quotes Numeric values do not need to be enclosed in quotes SELECT * FROM persons WHERE city=‘Sandnes’; Or WHERE city=“Sandnes”; WHERE P_Id=1;
15
WHERE Clause Operator Description = Equal <> Not equal >
Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Between an inclusive range LIKE Search for a pattern IN If you know the exact value you want to return for at least one of the columns
16
AND or OR AND, OR operators are used to filter records based on more than one condition AND=both the first and the second conditions is true OR=either the first or the second condition is true
17
AND or OR SELECT * FROM persons
WHERE firstname=‘Tove’ AND lastname=‘Svendson’; SELECT * FROM persons WHERE firstname=‘Tove’ OR firstname=‘Ola’; SELECT * FROM persons WHERE lastname=‘Svendson’ AND (firstname=‘Tove’ OR firstname=‘Ola’);
18
INSERT INTO Use to insert new records in a table
INSERT INTO table_name VALUES (value1, value2, value3,…); INSERT INTO table_name (column1, column2, column3, … VALUES (value1, value2, value3,…); INSERT INTO persons VALUES (4, ‘Nilsen’, ‘Tom’, ‘Vingvn23', 'Stavanger'); INSERT INTO persons (P_Id, lastname, firstname) VALUES (5, ‘Tjessem’, ‘Jakob’);
19
DELETE statement Used to delete records in a table
DELETE FROM table_name WHERE some_column=some_value; DELETE FROM persons WHERE lastname=‘Tjessem’ AND firstname=‘Jakob’; DELETE FROM table_name; Or DELETE * FROM table_name;
20
Creating a MySQL Database
Use phpMyAdmin to build a single Table Database. The database will be called addressbook and the table will be called friend. The table will include the following attributes: First name Last name Phone Birthday – A record will identified by this primary unique key
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.