Physically Detached Yet Academically Attached
Week 11
Lesson Title Server-Side Scripting
Discuss an interactive web-based application that uses server-side script
Learning Outcome(s) to process data than can retrieve valid rows of data by connecting PHP to
Database (MySQL) using MySQLi Connection method
At SJPIICD, I Matter!
LEARNING INTENT!
Terms to Ponder
Server Language a method of designing websites so that the
process or user request is run on the originating server
Interpreter is a computer program that
directly executes instructions written in a programming or scripting
language, without requiring them previously to have
been compiled into a machine language program.
ORDER BY clause is used to sort the result-set in ascending or descending order
UPDATE statement is used to update existing records in a table
Essential Content
Server-side scripting
A method of designing websites so that the process or user request
is run on the originating server. Server-side scripts provide an
interface to the user and limit access to proprietary data and help
keep control of the script source code
PHP MySQL Database
MySQL is the most popular database system used with PHP.
MySQL is a database system used on the web
MySQL is a database system that runs on a server
MySQL is ideal for both small and large applications
MySQL is very fast, reliable, and easy to use
MySQL uses standard SQL
MySQL compiles on a number of platforms
MySQL is free to download and use
MySQL is developed, distributed, and supported by Oracle
Corporation
Physically Detached Yet Academically Attached
PHP + MySQL Database System
x PHP combined with MySQL are cross-platform (you can develop in Windows
and serve on a Unix platform)
Should I Use MySQLi or PDO?
Both MySQLi and PDO have their advantages:
PDO will work on 12 different database systems, whereas MySQLi will only
work with MySQL databases.
So, if you have to switch your project to use another database, PDO makes
the process easy. You only have to change the connection string and a few queries.
With MySQLi, you will need to rewrite the entire code - queries included.
Open a Connection to MySQL
Before we can access data in the MySQL database, we need to be able to
connect to the server:
Create a MySQL Database Using MySQLi
The CREATE DATABASE statement is used to create a database
in MySQL.
The following examples create a database named "myDB":
Physically Detached Yet Academically Attached
Create a MySQL Table Using MySQLi
The CREATE TABLE statement is used to create a table in
MySQL.
We will create a table named "MyGuests", with five columns:
"id", "firstname", "lastname", "email" and "reg_date":
Physically Detached Yet Academically Attached
After the data type, you can specify other optional attributes for
each column:
x NOT NULL - Each row must contain a value for that column,
null values are not allowed
x DEFAULT value - Set a default value that is added when no
other value is passed
x UNSIGNED - Used for number types, limits the stored data to
positive numbers and zero
x AUTO INCREMENT - MySQL automatically increases the value
of the field by 1 each time a new record is added
x PRIMARY KEY - Used to uniquely identify the rows in a table.
The column with PRIMARY KEY setting is often an ID number,
and is often used with AUTO_INCREMENT
Physically Detached Yet Academically Attached
Insert Data Into MySQL Using MySQLi
After a database and a table have been created, we can start
adding data in them.
Here are some syntax rules to follow:
x The SQL query must be quoted in PHP
x String values inside the SQL query must be quoted
x Numeric values must not be quoted
x The word NULL must not be quoted
Here are some syntax rules to follow:
x The SQL query must be quoted in PHP
x String values inside the SQL query must be quoted
x Numeric values must not be quoted
x The word NULL must not be quoted
The INSERT INTO statement is used to add new records to a MySQL
table:
Physically Detached Yet Academically Attached
PHP MySQL Select Data
Select Data From a MySQL Database
The SELECT statement is used to select data from one or more
tables:
Physically Detached Yet Academically Attached
PHP MySQL Use The WHERE Clause
Select and Filter Data From a MySQL Database
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those records that
fulfil a specified condition.
Physically Detached Yet Academically Attached
PHP MySQL Use the ORDER BY Clause
The ORDER BY clause is used to sort the result-set in
ascending or descending order.
The ORDER BY clause sorts the records in ascending order by
default. To sort the records in descending order, use the DESC
keyword.
Physically Detached Yet Academically Attached
PHP MySQL Delete Data
Delete Data From a MySQL Table Using MySQLi
The DELETE statement is used to delete records from a table:
Physically Detached Yet Academically Attached
PHP MySQL Update Data
Update Data In a MySQL Table Using MySQLi and
The UPDATE statement is used to update existing records in a
table:
SELF-SUPPORT: You can click the URL Search Indicator below to help you further understand the lessons.
Search Indicator
x [Link]
[Link]#:~:text=Server%2Dside%20scripting%20is%20a,
of%20the%20script%20source%20code.
x [Link]