PHP. Basic SQL definition: Database A database which structures data in the form of tables. Each table contains information relevant to a particular.

Slides:



Advertisements
Similar presentations
 2003 Prentice Hall, Inc. All rights reserved. Chapter 22 – Database: SQL, MySQL, DBI and ADO.NET Outline 22.1 Introduction 22.2 Relational Database Model.
Advertisements

2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
CSE 1561 A Brief MySQL Primer Stephen Scott. CSE 1562 Introduction Once you’ve designed and implemented your database, you obviously want to add data.
Chapter 8 Special-Purpose Languages. SQL SQL stands for "Structured Query Language". Allows the user to pose complex questions of a database. It also.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
1 Introduction to Web Application Introduction to Data Base.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
SQL | PHP Tutorial at 8am. god, it’s early.. SQL intro There are many different versions of SQL available for usage. Oracle MySQL SQLite DB2 Mimer The.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
SQL advanced select using Oracle 1 7. Multiple Tables: Joins and Set Operations 8. Subqueries: Nested Queries.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Database and mySQL Week 07 Dynamic Web TCNJ Jean Chu.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Databases November 15, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Nikolay Kostov Telerik Corporation
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
PHP and Mysql Database. PHP and Database Mysql – popular open-source database management system PHP usually works with Mysql for web-based database applications.
CHAPTER 10 PHP MySQL Database
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
DAY 9: DATABASES Rohit February 17,
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
PHP & MY SQL Instructor: Monireh H. Sayadnavard 1.
Standard language for querying and manipulating data Structured Query Language Many standards out there: ANSI SQL, SQL92 (a.k.a. SQL2), SQL99 (a.k.a. SQL3),
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Web Systems & Technologies
 2012 Pearson Education, Inc. All rights reserved.
ISC440: Web Programming 2 Server-side Scripting PHP 3
SQL Tutorial.
PHP and MySQL.
Structured Query Language
Intro to Relational Databases
Web Programming Language
Charles Severance Single Table SQL.
PHP and MySQL.
MySQL Database System Installation Overview SQL summary
Presentation transcript:

PHP

Basic SQL

definition: Database A database which structures data in the form of tables. Each table contains information relevant to a particular feature, and is linked to other tables by a common value. For example, two attribute tables could be linked to a spatial data table via a Geocode, such as the postcode.

A very short explanation In one database. There are many tables. One table represents a set of entity. For example ‘People’, ‘Cars’, ‘Movies’ Table has many rows. One row in table represents instance of entities. For example Toni Meechai’, ‘Kobota Sedan’, ‘Twilight’ Table also has many column. One column represents property of an instance. For example Nationality’, ‘How fast’, ‘How boring it is’ When you want get or do something with Database Tables, you can query it like ‘Please show me all people’. Unfortunately, you have to follow SQL format.

Play with PHP MyAdmin Pay attention to demonstration. Try to understand ideas of ‘Database’, ‘Table’, ‘Row’, ‘Basic usage of SQL’. Learners can follow this article:

SQL : Selecting data

Selecting from 1 table SELECT * FROM COUNTRY; SELECT * FROM COUNTRY WHERE CONTINECT=‘ASIA’; SELECT CODE,NAME,CONTINENT,POPULATION FROM COUNTRY WHERE CONTINENT=‘ASIA’;

SELECT NAME,POPULATION FROM COUNTRY WHERE CONTINENT=‘ASIA’ ORDER BY POPULATION DESC; If we want to reverse it, change DESC to ASC instead

If it has many rows, we want just 10 rows SELECT NAME,POPULATION FROM COUNTRY WHERE CONTINENT=‘ASIA’ ORDER BY POPULATION DESC LIMIT 10;

If we want to change column name SELECT NAME AS “ ประเทศ สุ่ม ” FROM COUNTRY WHERE CONTINENT=‘ASIA’ ORDER BY RAND() LIMIT 10; NOTE, If you want to change name to be something like ประเทศ สุ่ม, it will throws an error Because that word contains whitespace.

List all countries started with ‘t’ SELECT NAME FROM COUNTRY WHERE NAME LIKE ‘T%’; List all countries ended with ‘land’ SELECT NAME FROM COUNTRY WHERE NAME LIKE ‘%land’; List all countries contains ‘ko’ SELECT NAME FROM COUNTRY WHERE NAME LIKE ‘%ko%’;

Tables joining Why joining? Refer to database course. It is better to store different content into different table. Reducing data redundant. MySQL, a database server we use is a Relational engine. We can say one table can has relationship to other tables. To get data across tables, we have to do joining selection.

Relationship in our 3 tables Consider our 3 tables: Country, City, CountryLanguage Table: Country has column ‘Code’ Table: City has column ‘CountryCode’ Table: CountryLanguage has column ‘CountryCode’ Country.Code, City.CountryCode, CountryLanguage.CountryCode are sharing relationship.

List all city in Thailand SELECT * FROM CITY,COUNTRY WHERE CODE=‘THA’ AND CODE=COUNTRYCODE; Remember. To join 2 tables we have to do 2 things. 1)Include 2 tables’name in From clause 2)Match the related columns in each 2 tables by using equality in where clause

If we have same columns name in 2 tables, you will get error cause there are ambiguous column names. To fix this problem, specific table name before column name by using.(dot) SELECT CITY.NAME,COUNTRY.NAME FROM CITY,COUNTRY WHERE CODE=‘THA’ AND COUNTRY.CODE=CITY.COUNTRYCODE;

Count and Sum Find surface area of Thailand + Malaysia SELECT SUM(SURFACEAREA) FROM COUNTRY WHERE NAME=‘THAILAND’ OR NAME=‘MALAYSIA’;

Find how many cities located in Asia SELECT COUNT(CITY.NAME) FROM CITY,COUNTRY WHERE CONTINENT=‘ASIA’ AND COUNTRY.CODE=CITY.COUNTRYCODE;

Changing Data Using SQL INSERT / UPDATE / DELETE

Prepare table first. CREATE TABLE Student ( id bigint(20) auto_increment PRIMARY KEY, varchar(255), firstname varchar(255), lastname varchar(255), nick varchar(255) );

Inserting — 1. Use SQL: “DESCRIBE tablename” to see the target table’s structure. Remember column name, type and sequence 2. Use SQL: “INSERT INTO VALUES(xxx,yyy,zzz)” Replace xxx,yyy,zzz with actual values you want to insert ordering as the table column’s sequence.

INSERT INTO student values( 1, ‘Taw’, ‘Poldee’, ‘Tawny’ );"

Updating — Updating SQL syntax is UPDATE tablename SET columnanme = newvalue WHERE condition

UPDATE student SET nick=‘Tawjung’ WHERE id=1;

Deleting Deleting SQL syntax is DELETE FROM tablename WHERE condition.

DELETE FROM student WHERE firstname=‘Taw’;

PHP interface with MySQL <?php mysql_connect("localhost:portnum", "user","password") or die(mysql_error()); mysql_select_db("dbname") or die(mysql_error()); $result = mysql_query("SELECT column1,column2 FROM tablename") or die(mysql_error()); while($row = mysql_fetch_array($result)) { print $row['column1']; print $row['column2']; } ?>