Home >Documents >PHP and MySQL Database

PHP and MySQL Database

Date post:27-Mar-2016
Category:
View:230 times
Download:9 times
Share this document with a friend
Description:
PHP and MySQL Database By Tin Htun Lwin
Transcript:
  • qwertyuiopasdfghjklzxcvbnmqwertyui

    opasdfghjklzxcvbnmqwertyuiopasdfgh

    jklzxcvbnmqwertyuiopasdfghjklzxcvb

    nmqwertyuiopasdfghjklzxcvbnmqwer

    tyuiopasdfghjklzxcvbnmqwertyuiopas

    dfghjklzxcvbnmqwertyuiopasdfghjklzx

    cvbnmqwertyuiopasdfghjklzxcvbnmq

    wertyuiopasdfghjklzxcvbnmqwertyuio

    pasdfghjklzxcvbnmqwertyuiopasdfghj

    klzxcvbnmqwertyuiopasdfghjklzxcvbn

    mqwertyuiopasdfghjklzxcvbnmqwerty

    uiopasdfghjklzxcvbnmqwertyuiopasdf

    ghjklzxcvbnmqwertyuiopasdfghjklzxc

    vbnmqwertyuiopasdfghjklzxcvbnmrty

    uiopasdfghjklzxcvbnmqwertyuiopasdf

    ghjklzxcvbnmqwertyuiopasdfghjklzxc

    vbnmqwertyuiopasdfghjklzxcvbnmqw

    PHP and MySQL Database [Type the document title]

    [Type the document subtitle]

    [Pick the date]

    SOELINAUNG

  • PHP and MySQL Database

    PHP and MySQL Database MySQL Database WAMP Server Wamp Install PHP ( - )

    MySQL Introduction

    MySQL Open Source Relational Database Management System MySQL Database American National Standards Institute- ANSI/ISO SQL Standard SQL (Structured Query Language) Standardlized language

    Open Source Relational Database Management System MySQL Database Objects Table Flexibility Data Data Database Engine

  • SQL : DML AND DDL

    Database Date ()

    Data Manipulating Language (DML)

    Data Definition Language (DDL)() Data Description Language (DDL)

    Data Manipulating Language (DML)

    DML database data

    SELECT - database data (Select From . Where)

    UPDATE - database data Update (Update Set Where)

    DELETE - database data Delete (Delete From Where)

    INSERT INTO - database data (Insert into ... Value ...)

    Data Definition Language (DDL) () Data Description Language (DDL)

    Database Table DDL statement

    CREATE DATABASE - Database

    ALTER DATABASE - Database

    CREATE TABLE - Database Table

    ALTER TABLE - Table

    DROP TABLE - Table

  • CREATE INDEX -

    DROP INDEX -

    () DML = Data Manipulation Language (SELECT,UPDATE,DELETE,INSERT INTO)

    Select Statement

    Select Statement Data Select

    MySQL SELECT Statement Syntax

    SELECT column_name(s)

    FROM table_name

    ()

    SELECT * FROM table_name

    asterisk (*) star shortcat table Columns Select

    employees Table

  • SELECT * FROM employees

    Select * Columns Select From

    employees employees table employees

    table Columns

    SELECT lastname,firstname,jobtitle

    FROM employees

  • employees table lastname,firstname,jobtitle column select

    conditional statement query Where Clause

    Where clause record where clause operator

    Text ( )

    Numeric ()

    SELECT column_name(s)

    FROM table_name

    WHERE column_name operator value

    -

    SELECT firstname,lastname,email

    FROM employees

  • WHERE jobtitle="president"

    employees table jobtitle column president row

    firstname,lastname,email

    Update Statement

    Update Statement Record edit Gmail Password

    MySQL Update Statement Syntax

    UPDATE table_name

    SET column_name=value, column_name=value2,...

    WHERE column_name

  • -

    +-----------+-----------+--------------------------------+ | lastname | firstname | email | +-----------+-----------+--------------------------------+ | m51a | thl | [email protected] | +-----------+-----------+--------------------------------+

    employees table Update

    UPDATE employees

    SET email = [email protected]

    WHERE employeeNumber = 1

    Email where

    clause set Column record

    +-----------+-----------+--------------------------------+ | lastname | firstname | email | +-----------+-----------+--------------------------------+ | m51a | thl | [email protected]| +-----------+-----------+--------------------------------+

    Delete Statement

    Delete Statement table row Record

    MySQL Delect Statement Syntax

    DELETE FROM table_name

    WHERE column_name

  • -

    DELETE FROMemployees

    WHERE lastname ='Murphy'

    Table

    DELETE FROM employees

    Insert Into Statement

    Insert Into Statement table row Insert Into

    column name

    column name

    MySQL Insert Into Statement Syntax

    INSERT INTO table_ Name

  • VALUES

    -

    Column Name

    INSERT INTO employees

    VALUES (Diane,'Murphy', '[email protected]')

    column name

    INSERT INTO employees (firstname,lastname,email)

    VALUES (Diane,'Murphy', '[email protected]')

    ()

  • () () WHERE clause

    SQL Where

    WHERE clause

    Where clause record where clause operator

    Text ( )

    Numeric ()

    MySQL WHERE clauseSyntax

    SELECT column_name(s)

    FROM table_name

    WHERE column_name / operator value

    -

    SELECT firstname,lastname,email

    FROM employees

    WHERE jobtitle="president"

  • employees table jobtitle column president row

    firstname,lastname,email

    WHERE Clause Operators -

    Equal , Not Equal, .. PHP

  • Between Operator

    BETWEEN Operator

    Between operator Number Text Date data

    select WHERE Clause

    SQL BETWEEN Syntax

    SELECT column_name(s)

    FROM table_name

    WHERE column_name

    BETWEEN value1 AND value2

    - tblCompany Table

    SELECT * FROM tblCompany

    WHERE Sales

    BETWEEN 10000 AND 19000

    tblCompany Table Sale Column 10000 19000 Select

  • NOT BETWEEN

    -

    SELECT * FROM tblCompany

    WHERE Sales

    NOT BETWEEN 10000 AND 19000

    Not Between 10000 19000 Select

  • LIKE Operator

    Like operator Column Date

    SQL LIKE Syntax

    SELECT column_name(s)

    FROM table_name

    WHERE column_name LIKE pattern;

    - tblCompany Table

    SELECT * FROM tblCompany

    WHERE Town

    LIKE H%;

    H %

    % wildcards wildcards Data

  • wildcards wildcards WHERE Clause

    wildcards

    IN Operator

    In operator WHERE clause

    SQL IN Syntax

    SELECT column_name(s)

    FROM table_name WHERE column_name IN (value1,value2,value3...)

    - tblCompany Table

    SELECT * FROM tblCompany

    WHERE Town

    IN (Pisa, Hamburg);

    tblCompany Table Town Column Pisa Hamburg Select

  • () () SQL

    SQL SQL

    PHP

    MySQL () SQL

    ()

    PHP Database PHP, MySQL Apache

    Package WAMP Wamp Server Install

    Create New Database

    Table Database Wamp Server Database

    Browser http://localhost/phpmyadmin/

    Localhost Enter Wamp Home Page Tools PHPmyadmin Tool

    Browser Wamp Server Taskbar

    WAMPServer image icon Click phpMyAdmin Select

  • Create New Database DB Name

    m51a_db Collation

    utf8_general_ci Create

  • DB

    Creating a New User

    Database User Privileges Click

    Add a new User Click Add a New User Open

    new phpMyAdmin window Click

  • User Name

    Host localhost Password

    m51a

    Global privileges Check All Go

  • User

    ()

    ()

  • () Database User

    Database Table

    Table phpMyadmin

    DB Name Click m51a_db

  • Create new table on database Name members Number of fields:

    Go

    Field row id Type INT length value 10

    Extra auto_increment PRIMARY KEY

    length value input character

    Save Members Table

    member Click

    members table members table Menu Insert

    Click Go

  • Data Menu Browse

    members Table SQL Statement DB

    Menu SQL Click

    CREATE TABLE ` members` (

    `id` int(10) NOT NULL auto_increment,

    `username` varchar(65) NOT NULL default '',

    `password` varchar(65) NOT NULL default '',

    PRIMARY KEY (` id`)

  • ) TYPE=MyISAM AUTO_INCREMENT=2 ;

    --

    -- Dumping data for table `members`

    --

    INSERT INTO `members` VALUES (1, m51a, '1234');

    DB Table PHP Login Script

    PHP C:wamp www folder login Folder

    login.php, checklogin.php , login_success.php page

    login.php Coding

    Member Login

    Username:

  • Password:

    Page HTML Table Login Box

    Page Form method="post"

    Post Method action="checklogin.php" Submit

    checklogin.php

    checklogin.php username Pw DB Name

    Database DB name username Password

  • $db_name="m51a_db"; // Database name

    $tbl_name="members"; // Table name

    // Connect to server and select databse.

    mysql_connect("$host", "$username", "$password")or die("cannot connect");

    mysql_select_db("$db_name")or die("cannot select DB");

    // username and password sent from form

    $myusername=$_POST['myusername'];

    $mypassword=$_POST['mypassword'];

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

    $result=mysql_query($sql);

    // Mysql_num_row is counting table row

    $count=mysql_num_rows($result);

    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==1){

    // Register $myusername, $mypassword and redirect to file "login_success.php"

    session_register("myusername");

  • session_register("mypassword");

    header("location:login_success.php");

    }

    else {

    echo "Wrong Username or Password";

    }

    ?>

    PHP PHP

    Variable PHP Page

    Mail

    mysql_connect("$host", "$username", "$password")or die("cannot connect");

    mysql_connect Database Data Access Connection

    mysql_connect() function PHP Page Database

    Connection Syntax -

    mysql_connect(servername,username,password);

    or die("cannot connect") Variable $host $username $password Data

    cannot connect

  • mysql_select_db("$db_name") mysql_select_db()function $db_name Select

    login_success.php Coding Page Login Login

    Successful

    Login Successful (PHP & MySQL Lesson - 5)

    Browser Localhost Enter

    Wamp Home Page Your projects www

  • Folder Click login.php

    ()

Click here to load reader

Reader Image
Embed Size (px)
Recommended