presentation2 - sql / mysql database basic

32
Web Programming PHP & MySql – Introductions

Upload: thirumalai-kumar

Post on 24-Jan-2017

75 views

Category:

Education


2 download

TRANSCRIPT

Page 1: Presentation2 - SQl / MySql Database Basic

Web Programming PHP & MySql – Introductions

Page 2: Presentation2 - SQl / MySql Database Basic

Required Skills

• Basic Front-end Designing

• Basic Digital Graphic Designing

• Programming Skills

• Database Concept

• Project Management Strategy

Page 3: Presentation2 - SQl / MySql Database Basic

Front-End Developer• Normal Design vs Responsive Design

Page 4: Presentation2 - SQl / MySql Database Basic

Web Project Management• Page / Directory Structure

Page 5: Presentation2 - SQl / MySql Database Basic

Digital Image Designing

• Image dimension

• Resolution

• Format

• Optimizations Technique

• Image Attributes

Page 6: Presentation2 - SQl / MySql Database Basic

Database Concepts• Create, Insert, Update, Delete..etc with

PHP in MySql Database

Page 7: Presentation2 - SQl / MySql Database Basic

Programming Skills

• Data type, Variables and Class

• Condition Statements

• Looping Statements

• Array Concept

• MySql - Query

Page 8: Presentation2 - SQl / MySql Database Basic

Database Management SystemDatabase is a collection of related data and data is a collection of facts and figures that can be processed to produce information. Mostly data represents recordable facts. Data aids in producing information, which is based on facts. For example, if we have data about marks obtained by all students, we can then conclude about toppers and average marks. A database management system stores data in such a way that it becomes easier to retrieve, manipulate, and produce information.

DBMS

End-User

Administrator

Designer

Page 9: Presentation2 - SQl / MySql Database Basic

DBMS - Architecture• 3-tier Architecture

Page 10: Presentation2 - SQl / MySql Database Basic

DBMS - Data Models• Sample 1

Page 11: Presentation2 - SQl / MySql Database Basic

Sample Sql – DB Create Query Create DB• CREATE DATABASE dbname;Ex: CREATE DATABASE my_db;

SQL CREATE TABLE SyntaxCREATE TABLE table_name

(column_name1 data_type(size),column_name2 data_type(size),column_name3 data_type(size),....);

Page 12: Presentation2 - SQl / MySql Database Basic

Example 1• CREATE TABLE Persons

(PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));

Page 13: Presentation2 - SQl / MySql Database Basic

Example 2• CREATE TABLE PersonsNotNull

(P_Id int NOT NULL,LastName varchar(255) NOT NULL,FirstName varchar(255),Address varchar(255),City varchar(255))

Page 14: Presentation2 - SQl / MySql Database Basic

Example 3• CREATE TABLE Persons

(P_Id int NOT NULL UNIQUE,LastName varchar(255) NOT NULL,FirstName varchar(255),Address varchar(255),City varchar(255))

Page 15: Presentation2 - SQl / MySql Database Basic

Example 4• CREATE TABLE Persons

(P_Id int NOT NULL PRIMARY KEY,LastName varchar(255) NOT NULL,FirstName varchar(255),Address varchar(255),City varchar(255))

Page 16: Presentation2 - SQl / MySql Database Basic

SQL FOREIGN KEY

Page 17: Presentation2 - SQl / MySql Database Basic

Example: Foreign-Key• CREATE TABLE Orders

(O_Id int NOT NULL,OrderNo int NOT NULL,P_Id int,PRIMARY KEY (O_Id),FOREIGN KEY (P_Id) REFERENCES Persons(P_Id))

Page 18: Presentation2 - SQl / MySql Database Basic

AUTO INCREMENT a Field

• CREATE TABLE Persons(ID int NOT NULL AUTO_INCREMENT,LastName varchar(255) NOT NULL,FirstName varchar(255),Address varchar(255),City varchar(255),PRIMARY KEY (ID))

Page 19: Presentation2 - SQl / MySql Database Basic

PHP + MySQL Database System• Insert Data Into MySQLINSERT INTO table_name (column1, column2, column3,...)VALUES (value1, value2, value3,...)

• PHP Delete Data From MySQLDELETE FROM table_name WHERE some_column = some_value

• PHP Update Data in MySQLUPDATE table_name SET column1=value, column2=value2,...WHERE some_column=some_value 

• PHP Limit Data Selections From MySQLSELECT * FROM Orders LIMIT 30

Page 20: Presentation2 - SQl / MySql Database Basic

PHP Connect to MySQL• <?php

$servername = "localhost";$username = "username";$password = "password";

// Create connection$conn = new mysqli($servername, $username, $password);

// Check connectionif ($conn->connect_error) {    die("Connection failed: " . $conn->connect_error);} echo "Connected successfully";?>

Page 21: Presentation2 - SQl / MySql Database Basic

PHP Conditional Statements• if statement - executes some code if one

condition is true• if...else statement - executes some code if

a condition is true and another code if that condition is false

• if...elseif....else statement - executes different codes for more than two conditions

• switch statement - selects one of many blocks of code to be executed

Page 22: Presentation2 - SQl / MySql Database Basic

Syntax

• if (condition) {    code to be executed if condition is true;}

• if (condition) {    code to be executed if condition is true;} else {    code to be executed if condition is false;}

• if (condition) {    code to be executed if this condition is true;} elseif (condition) {    code to be executed if this condition is true;} else {    code to be executed if all conditions are false;}

Page 23: Presentation2 - SQl / MySql Database Basic

Example• <?php

$t = date("H");

if ($t < "10") {    echo "Have a good morning!";} elseif ($t < "20") {    echo "Have a good day!";} else {    echo "Have a good night!";}?>

Page 24: Presentation2 - SQl / MySql Database Basic

PHP switch Statement• switch (n) {

    case label1:        code to be executed if n=label1;        break;    case label2:        code to be executed if n=label2;        break;    case label3:        code to be executed if n=label3;        break;    ...    default:        code to be executed if n is different from all labels;}

• <?php$favcolor = "red";

switch ($favcolor) {    case "red":        echo "Your favorite color is red!";        break;    case "blue":        echo "Your favorite color is blue!";        break;    case "green":        echo "Your favorite color is green!";        break;    default:        echo "Your favorite color is neither red, blue, nor green!";}?>

Page 25: Presentation2 - SQl / MySql Database Basic

PHP Loops

• while - loops through a block of code as long as the specified

condition is true

• do...while - loops through a block of code once, and then

repeats the loop as long as the specified condition is true

• for - loops through a block of code a specified number of times

• foreach - loops through a block of code for each element in an

array

Page 26: Presentation2 - SQl / MySql Database Basic

While Loops• while (condition is true) {

    code to be executed;} <?php 

$x = 1; 

while($x <= 5) {    echo "The number is: $x <br>";    $x++;} ?>

Page 27: Presentation2 - SQl / MySql Database Basic

do...while Loop• do {

    code to be executed;} while (condition is true);

• <?php $x = 1; 

do {    echo "The number is: $x <br>";    $x++;} while ($x <= 5);?>

Page 28: Presentation2 - SQl / MySql Database Basic

PHP for Loop• for (init counter; test counter; increment counter) {

    code to be executed;}

• <?php for ($x = 0; $x <= 10; $x++) {    echo "The number is: $x <br>";} ?>

Page 29: Presentation2 - SQl / MySql Database Basic

PHP foreach Loop• foreach ($array as $value) {

    code to be executed;}

• <?php $colors = array("red", "green", "blue", "yellow"); 

foreach ($colors as $value) {    echo "$value <br>";}?>

Page 30: Presentation2 - SQl / MySql Database Basic

Web Designer Skills

Page 31: Presentation2 - SQl / MySql Database Basic
Page 32: Presentation2 - SQl / MySql Database Basic