0% found this document useful (0 votes)
26 views

Lecture 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lecture 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

College of Computer Science and

Information Technology

Web Technologies II

Assist. Prof. Dr Mohammed Mohsin Al-Ebady


Headline
1. Introduction
2. Design Concepts
– Abstraction
– Refinement
– Modularity
3. PHP & MySQL
Introduction
The main goal of Web application design
is to facilitate the understanding of the
solution that is going to be developed (i.e.,
the Web application), as opposed to the
understanding of the users and the context
in which the solution is deployed, which is
addressed by requirements engineering
Web applications distinguish themselves
from regular software systems.
Naturally, this distinction equally applies
to Web application design. The most
important peculiarities of the Web
application domain that require specific
design approaches are:
• Higher accessibility of information and
services
• Document-centric hypertext interface
• Different data management, data access,
and processing technologies
• Variable presentation technologies and
engines
• More complex architectures
Design Concepts
While the implications of the Web
environment on Web application design
require new design abstractions to
capture various perspectives, different
from those adopted for traditional
software systems, general principles and
concepts stay valid.
Abstraction
Abstraction is one of the main design
principles to manage the complexity of
software (and Web) applications.
Abstraction allows us to concentrate on a
problem at some level of generalization,
independently of low-level implementation
details. There are many ways to take
advantage of abstractions in the
development of software projects.
domain-oriented abstraction
use of application domain terminology to facilitate the interactions with the user or the
customer
Solution-oriented abstraction
exploits objects, classes or procedures facilitate the discussion of the software organization
within the development team
The procedural abstraction
looking at named sequences of instructions

Data abstraction
looking at named collections of data

Control abstraction
looking at program control mechanisms
Web engineering community two main approaches
have emerged depending on whether the application
development is approached from an information or
a user perspective:
1- Information-centric design processes start
with activities related to the
back-end of an information system.
2- User-centric design processes start
from the analysis of the users’ activities.
Workflow design is thus the first step, and
the resulting workflow serves as an input
for navigation design where workflows
are transformed into sequences of
navigation steps.
Refinement
Refinement goes hand in hand with abstraction.
As a design process continues,
stepwise refinement of the abstractions is
employed to clarify the details of the
designs and its transformations to the models
closer to the implementation
environment. Refinement plays a crucial role in
Web application design as well.
Depending on the chosen approach, the navigation models
refine either data models or workflow models. Similarly,
presentation models are refinements of the navigation models.
The data, navigation, and presentation models are
mapped onto the architecture that describes the overall
organization of the Web application. Structural partitioning is a
common approach to structure a system for
follow-up refinements. The partitioning can be horizontal or
vertical.
Modularity
Modularity is a principle of software system design
that enables the software to be manageable. The
software is decomposed into a set of modules that
are integrated to satisfy the collected requirements.
Modularity contributes to better understandability of
the subproblems the software is supposed to solve,
to better integrability, and to easier introduction of
changes that do not affect the whole system; it also
reduces the impact of failures to specific
submodules.
PHP & MySQL
Functions
• Functions MUST be defined before then can be
called
• Function headers are of the format
function functionName($arg_1, $arg_2, …, $arg_n)
– Note that no return type is specified
• Unlike variables, function names are not case
sensitive (foo(…) == Foo(…) == FoO(…))
Functions example
<?php
// This is a function
function foo($arg_1, $arg_2)
{
$arg_2 = $arg_1 * $arg_2;
return $arg_2;
}

$result_1 = foo(12, 3); // Store the function


echo $result_1; // Outputs 36
echo foo(12, 3); // Outputs 36
?>
MySQL Connectivity
• mysqli_connect()
– The mysqli_connect()function opens a non-persistent
MySQL connection.
– This function returns the connection on success, or FALSE
and an error on failure. You can hide the error output by
adding an '@' in front of the function name.
• Syntax
– mysqli_connect(server,user,pwd)
Parameter Description
server Specifies the server to connect to
user Specifies the username to log in with.
pwd Specifies the password to log in with.
MySQL Connectivity
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = mysqli_connect($servername, $username,
$password);
// Check connection
if (!$conn) {
die("Connection failed: " .
mysqli_connect_error());
}
echo "Connected successfully";
?>
• mysqli_close()
– The mysql_close() function closes a non-persistent
MySQL connection.
– This function returns TRUE on success, or FALSE on
failure.
• Syntax:
– mysqli_close(connection)
Parameter Description
connection Specifies the MySQL connection to close. If not
specified, the last connection opened by
mysqli_connect() is used.
MySQL Query
Syntax:
Object oriented style:
$mysqli -> query(query, resultmode)
Procedural style:
mysqli_query(connection, query, resultmode)

Parameter Values

Parameter Description

connection Required. Specifies the MySQL connection to use

query Required. Specifies the SQL query string


Create Database
$servername = "localhost";
$username = "username";
$password = "password";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "CREATE DATABASE myDB";
if (mysqli_query($conn, $sql)) {
echo "Database created successfully";
} else {
echo "Error creating database: " . mysqli_error($conn);
}
mysqli_close($conn);
Select Database and Connect
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username,
$password, $dbname);
Create Table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDAT
CURRENT_TIMESTAMP)";
if (mysqli_query($conn, $sql)) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn)
}
Insert Data
$sql = "INSERT INTO MyGuests (firstname, lastname,
email)
VALUES ('John', 'Doe', '[email protected]')";

if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" .
mysqli_error($conn);
}
Insert Multiple
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]');";
$sql .= "INSERT INTO MyGuests (firstname, lastname,
email)
VALUES ('Mary', 'Moe', '[email protected]');";
$sql .= "INSERT INTO MyGuests (firstname, lastname,
email)
VALUES ('Julie', 'Dooley', '[email protected]')";
if (mysqli_multi_query($conn, $sql)) {
echo "New records created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
Delete Data
// sql to delete a record
$sql = "DELETE FROM MyGuests WHERE id=3";

if ($conn->query($sql) === TRUE) {


echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
Update Data
$sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2";

if ($conn->query($sql) === TRUE) {


echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
Associated Array
mysqli_fetch_array
mysqli_fetch_assoc
Thank You

You might also like