Presentation2 - SQl / MySql Database Basic
-
Upload
thirumalai-kumar -
Category
Education
-
view
69 -
download
2
Transcript of Presentation2 - SQl / MySql Database Basic
Web Programming PHP & MySql – Introductions
Required Skills
• Basic Front-end Designing
• Basic Digital Graphic Designing
• Programming Skills
• Database Concept
• Project Management Strategy
Front-End Developer• Normal Design vs Responsive Design
Web Project Management• Page / Directory Structure
Digital Image Designing
• Image dimension
• Resolution
• Format
• Optimizations Technique
• Image Attributes
Database Concepts• Create, Insert, Update, Delete..etc with
PHP in MySql Database
Programming Skills
• Data type, Variables and Class
• Condition Statements
• Looping Statements
• Array Concept
• MySql - Query
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
DBMS - Architecture• 3-tier Architecture
DBMS - Data Models• Sample 1
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),....);
Example 1• CREATE TABLE Persons
(PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));
Example 2• CREATE TABLE PersonsNotNull
(P_Id int NOT NULL,LastName varchar(255) NOT NULL,FirstName varchar(255),Address varchar(255),City varchar(255))
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))
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))
SQL FOREIGN KEY
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))
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))
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
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";?>
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
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;}
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!";}?>
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!";}?>
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
While Loops• while (condition is true) {
code to be executed;} <?php
$x = 1;
while($x <= 5) { echo "The number is: $x <br>"; $x++;} ?>
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);?>
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>";} ?>
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>";}?>
Web Designer Skills