Development Technologies. Agenda: phpmyadmin 2/20/2016. phpmyadmin MySQLi. Before you can put your data into a table, that table should exist.

Similar documents
Lecture 13: MySQL and PHP. Monday, March 26, 2018

Networks and Web for Health Informatics (HINF 6220) Tutorial 13 : PHP 29 Oct 2015

Fundamentals of Web Technologies. Agenda: CSS Layout (Box Model) CSS Layout: Box Model. All HTML elements can be considered as a box or a container

Download and Installation Instructions: After WAMP Server download start the installation:

MySQL: Access Via PHP

MySQL: Querying and Using Form Data

IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population

Database Connectivity using PHP Some Points to Remember:

Use of PHP for DB Connection. Middle and Information Tier. Middle and Information Tier

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008.

PHP and MySQL Programming

PHP Development - Introduction

Using PHP with MYSQL

Locate your Advanced Tools and Applications

Chapter 10: MySQL & PHP. PHP and MySQL CIS 86 Mission College

COMP284 Scripting Languages Lecture 13: PHP (Part 5) Handouts

Use of PHP for DB Connection. Middle and Information Tier

I n p u t. This time. Security. Software. sanitization ); drop table slides. Continuing with. Getting insane with. New attacks and countermeasures:

Installing Joomla

Chapters 10 & 11 PHP AND MYSQL

Advanced Web Tutorial 10

WEB SECURITY: SQL INJECTION

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

Courtesy of Clayton Fyfe. Lab 2 Runthrough

Mysql Tutorial Create Database Username Password Through Phpmyadmin

DATABASES SQL INFOTEK SOLUTIONS TEAM

Announcements. PS 3 is out (see the usual place on the course web) Be sure to read my notes carefully Also read. Take a break around 10:15am

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley

CSCE 548 Building Secure Software SQL Injection Attack

This lecture. PHP tags

Databases PHP I. (GF Royle, N Spadaccini ) PHP I 1 / 24

Web Application Development (WAD) V th Sem BBAITM (Unit 4) By: Binit Patel

SQL. Often times, in order for us to build the most functional website we can, we depend on a database to store information.

2017 Politecnico di Torino 1

2017 Politecnico di Torino 1

COMP519: Web Programming Autumn 2015

CHAPTER 10. Connecting to Databases within PHP

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Programming in Java

Introduction to MySQL. Database Systems

Database connection 1

Fundamentals of Web Technologies. Agenda: HTML Links 5/22/2017. HTML Links - Hyperlinks HTML Lists

COMS 469: Interactive Media II

CSC 215 PROJECT 2 DR. GODFREY C. MUGANDA

Locate your Advanced Tools and Applications

Joomla 3.X Global Settings Part III Server Settings

PHP: Hypertext Preprocessor. A tutorial Introduction

DATABASE SYSTEMS. Introduction to MySQL. Database System Course, 2016

Web Security. Jace Baker, Nick Ramos, Hugo Espiritu, Andrew Le

HTML Forms & PHP. Database Systems CSCI Dr. Tom Hicks Computer Science Department

Chapter 7 PHP Files & MySQL Databases

PHP Queries and HTML Forms Lecture 23

PHP & MySQL Database. Database Systems CSCI Dr. Tom Hicks Computer Science Department

AN INTRODUCTION TO WEB PROGRAMMING. Dr. Hossein Hakimzadeh Department of Computer and Information Sciences Indiana University South Bend, IN

Host at 2freehosting.Com

Draft. Students Table. FName LName StudentID College Year. Justin Ennen Science Senior. Dan Bass Management Junior

MYSQL DATABASE ACCESS WITH PHP

The MANUAL. 1 P a g e

Installing LAMP on Ubuntu and (Lucid Lynx, Maverick Meerkat)

Module - P7 Lecture - 15 Practical: Interacting with a DBMS

More loops. Control structures / flow control. while loops. Loops / Iteration / doing things over and over and over and over...

Professional PHP for working with MySQL

DR B.R.AMBEDKAR UNIVERSITY B.Sc.(Computer Science): III Year THEORY PAPER IV (Elective 4) PHP, MySQL and Apache

PHP Querying. Lecture 21. Robb T. Koether. Hampden-Sydney College. Fri, Mar 2, 2018

Getting Started with Mathematica

Web Security. Attacks on Servers 11/6/2017 1

DATABASE SYSTEMS. Introduction to MySQL. Database System Course, 2016

Introduction to MySQL. Database Systems

Full Stack Web Developer

ITC 250/CPET 499 Web Systems Nov. 3, 2016 Managing MySQL Database Part 3 of 3

Advanced Web Technology 10) XSS, CSRF and SQL Injection

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

CSE 127: Computer Security SQL Injection. Vector Li

LAMP Apps. Overview. Learning Outcomes: At the completion of the lab you should be able to:

CS317 File and Database Systems

Application vulnerabilities and defences

Running SQL in Java and PHP

Database Systems. phpmyadmin Tutorial

Joomla Pre-install Tasks

CSCI 4000 Assignment 6

Lecture 7: Web hacking 3, SQL injection, Xpath injection, Server side template injection, File inclusion

Using MySQL on the Winthrop Linux Systems

This lecture. Databases - JDBC I. Application Programs. Database Access End Users

Module 3 MySQL Database. Database Management System

CSCI 4000 Assignment 5

Running SQL in Java and PHP

PHPRad. PHPRad At a Glance. This tutorial will show you basic functionalities in PHPRad and

INSTALLING RACHEL ON SYNOLOGY GIAKONDA IT

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310

Computer Fundamentals & MS OFFICE. (OR : batch. only) Computer Fundamentals and Photoshop. (NR : onwards )

Networks and Web for Health Informatics (HINF 6220)

! Quick review of ! normalization! referential integrity ! Basic MySQL ! Other types of DBs

SQL Injection Attack Lab

PHP Arrays. Lecture 20. Robb T. Koether. Hampden-Sydney College. Wed, Feb 28, 2018

CSCI 4000 Assignment 4

Real Web Development. yeah, for real.

Project Title REPRESENTATION OF ELECTRICAL NETWORK USING GOOGLE MAP API. Submitted by: Submitted to: SEMANTA RAJ NEUPANE, Research Assistant,

UNIVERSITY OF BOLTON CREATIVE TECHNOLOGIES HND/BSC (HONS) COMPUTING & WEBSITE DEVELOPMENT SEMESTER TWO EXAMINATION 2016/2017

BSc (Hons) Web Technologies. Examinations for 2017 / Semester 1

Chapter 1 An introduction to relational databases and SQL

Transcription:

CIT 736: Internet and Web Development Technologies Lecture 10 Dr. Lupiana, DM FCIM, Institute of Finance Management Semester 1, 2016 Agenda: phpmyadmin MySQLi phpmyadmin Before you can put your data into a table, that table should exist. A table, however, cannot exist on its own; it should belong to a certain database. A database belongs to a user account of an application called Database Management System (DBMS) 1

phpmyadmin A DBMS can have one or more user accounts A user account in a DBMS can have one or more databases A DBMS is a software for creating and managing (create, retrieve and update data) databases. phpmyadmin phpmyadmin is a tool that enables you to easily interact with MySQL DBMS (often referred to as MySQL database) Through phpmyadmin, interaction to MySQL is through a Web browser. To access phpmyadmin in your local machine you type: localhost/phpmyadmin in the address bar of a Web browser phpmyadmin By default, a root user account is used This account does not have a password and hence you will not asked to type a password One you are in this account, you can create a database and a table Once you have created a table, you can change its structure, insert, delete, update etc 2

Introduction to MySQLi MySQLi is an extension to MySQL MySQLi stands for MySQL improved MySQLi offers many benefits such as; An Object-Oriented interface Support prepared statements which are useful for security purposes Introduction to MySQLi We mainly use mysql class to establish a connection with a database and thereafter manipulate it new operator is used to create a new instance/object of mysqli class Thus, the newly created instance inherit all attributes and functions (methods) defined in the mysqli class Introduction to MySQLi The resultant instance/object, which is stored in a memory somewhere, can be accessed through the assigned variable (in this case $conn) This variable is called reference variable 3

Introduction to MySQLi To access an attribute or a method of an object, object operator (-> ) is used. This is done by typing the name of a reference variable followed by the object operator and name of an attribute or a method Establishing a DB Connection To insert or retrieve data from a database, you first need to establish a connection to the database To establish a connection, we need to know four things; Host (where a DBMS is hosted) Username Password Database name Establishing a DB Connection We are going to use mysqli class to create an object This object is created by specifying host, username, password and database name 4

Establishing DB Connection <?php $host = localhost ; $username = root ; $pwd = ; $db = mazoezi ; $conn = new mysqli($host, $username, $pwd, $db);?> * Assumption here is that a database called mazoezi exists in the MySQL DBMS Inserting Data in a Table Once a connection is established, data in database tables can be inserted, retrieved, deleted or updated We can insert data into a table in two ways; Using old traditional way Using prepared statements Using Old Traditional Way *Assumption here is that the data comes from an HTML form that has two textboxes called fname and sname 5

Using Old Traditional Way First you need to define your insert statement and store it in a variable as a string (line 6) Then use query method (line 7) to execute the query The query method takes string as an argument (in this case the insert statement) The query method, in this case, returns true if the query is executed without an error and false if otherwise Using Old Traditional Way Thereafter use close method (line 8) of mysqli instance to close the database connection This method, however, is prone to SQL injection and hence not secure Using Prepared Statements *Assumption here is that the data comes from an HTML form that has two textboxes called fname and sname 6

Using Prepared Statements First you need to define your insert statement and store it in a variable as a string (line 6) You then need to use a prepare method (or function) of mysqli instance (or object) to prepare the statement (line 7) The prepare method takes string as an argument (in this case the insert statement) The prepare method returns an object (thus a reference variable needs to be used) Using Prepared Statements Thereafter, use bind_param method (line 8) of the object created in line 7 to bind arguments (i.e. values) with parameters (question marks in the insert statement) The first argument of the bind_param method specify data types of the arguments In this case the data type of the two arguments is string Using Prepared Statements Then, use execute method (line 9) of the object created in line 7 to execute the prepared statement Then use close method (line 10) of the object created in line 7 to close the prepared statement Thereafter use close method (line 11) of mysqli instance to close the database connection 7

First you need to define your select statement and store it in a variable as a string (line 4) You then need to use a query method of mysqli instance to execute the query (line 5) The query method takes string as an argument (in this case the select statement) The query method, in this case, returns an object (thus a reference variable needs to be used) The object created in line 5 contains all rows (with their attributes) from the table We want to access each row and display its attributes To do this, we need to use loop and a fetch_assoc method (line 6) of the object created in line 5 8

Since the target table might be empty, we use while loop to ensure we are not attempting to display an empty row The fetch_assoc method returns a row of a table from the object created in line 5 Thus, the returned row (which is an array of attributes) needs to be stored in order to display its attributes (thus a variable needs to be used) In each loop items of a returned array are displayed by referring to the names of the items in the array (line 7) In this case names of the items are names of attributes as specified in the table Thereafter use close method (line 10) of mysqli instance to close the database connection 9