Module 3. 1. Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.

Slides:



Advertisements
Similar presentations
Objectives Connect to MySQL from PHP
Advertisements

MySQL and PHP By Trevor Adams.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
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,
CSCI 6962: Server-side Design and Programming
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
INTERNET APPLICATION DEVELOPMENT For More visit:
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
 Mysql – popular open-source database management system  PHP usually works with Mysql for web- based database applications  LAMP applications—Web-based.
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 What is database 2? What is normalization? What is SQL? What is transaction?
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
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,
PHP and Mysql Database. PHP and Database Mysql – popular open-source database management system PHP usually works with Mysql for web-based database applications.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Accessing mySQL relational database. MySQL database.  Today, we will attempt and open a connection to the MySQL server.  We need to specify the database.
PHP: MySQL. PHP Connect to MySQL PHP 5 and later can work with a MySQL database using: – MySQLi extension (the "i" stands for improved) – PDO (PHP Data.
PHP Database Pemrograman Internet. PHP MySQL Database With PHP, you can connect to and manipulate databases. MySQL is the most popular database system.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
CHAPTER 10 PHP MySQL Database
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
OBJECTIVES Learn how to view data using SQL and PHP Learn how to add new data using SQL and PHP PHP+SQL: View and Adding,
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Lecturer: Eng. Mohamed Adam Isak PH.D Researcher in CS. M.Sc. and B.Sc. of Information Technology Engineering Senior Lecturer in University of Somalia,
SQL Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database.
 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.
Web Systems & Technologies
Module T03d Software Engineering
CHAPTER 7 DATABASE ACCESS THROUGH WEB
CS320 Web and Internet Programming SQL and MySQL
Introduction to Web programming
Using SQL Server through Command Prompt
ISC440: Web Programming 2 Server-side Scripting PHP 3
Introduction To Structured Query Language (SQL)
SQL Queries Chapter No 3.
Introduction To Structured Query Language (SQL)
Structured Query Language
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Introduction to Web programming
Presentation transcript:

Module 3

1. Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in PHP

Standard Query Language

 SQL stands for Structured Query Language  SQL is a standard language for accessing databases.  MySQL, SQL Server, Access, Oracle, Sybase, DB2, and other database systems.  SQL lets you access and manipulate databases  SQL is an ANSI (American National Standards Institute) standard

 Although SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language.  However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.  Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!

 To build a web site that shows some data from a database, you will need the following: An RDBMS database program (i.e. MS Access, SQL Server, MySQL) A server-side scripting language, like PHP or ASP SQL HTML / CSS

 CREATE DATABASE database_name Eg. Create database friends;

 A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data.

 CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type,.... )

 CREATE TABLE Friends ( idnumber int, LastName varchar(255), FirstName varchar(255), Age varchar(255), Gender varchar(255) )

 Constraints are used to limit the type of data that can go into a table.  Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement). NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY CHECK DEFAULT

Id_numberLastnameFirstnameAgeGender 0001AgcopraJim21M 0002AgcopraJoseph26M 0003GalamitonPalquincy21M 0004BelonoCyril22F 0005GenerKathleen30F 0006De CastroRose Ann23F 0007CastilloJoan Rose28F 0008LlanderalJoan Rey29F 0009CarbonellAndrew27M 0010RoaBambi Rey28M 0011AgcopraJason28M

 The SELECT statement is used to select data from a database.  The result is stored in a result table, called the result-set.  SQL SELECT Syntax SELECT column_name(s) FROM table_name  and SELECT * FROM table_name

 and SELECT * FROM table_name WHERE [Conditions] Eg. Select * From ekek where lastname = ‘Gargar’;

 SELECT * FROM NAMES  SELECT Lastname,Firstname From Names  SELECT * FROM Names Where Lastname = ‘Agcopra’  SELECT * FROM Names Where Firstname like ‘A%’;  Select * From Names Where Age > 25 AND Gender = ‘M’

Standard Query Language

 Know your HTMLS  Know common PHP Commands and Structures  Master your SQL

1. Check if there is an PHP-SQL connection 2. Use a Database 3. Get a Table and Execute Queries 4. Extract Data from the Queries. 5. Close your Database after use.

<?php $connection = mysql_connect(‘localhost’,’root’,’password’) or die (‘Unable to Connect’); if($connection!=NULL) { echo "SQL is Connected to PHP"; }

mysql_select_db('friends') or die ('Unable to select a database!');

$query = 'Select * FROM names'; $result = mysql_query($query) or die (‘error in query’); ('Error in query: $query. '. msql_error());

 There are 3 different ways to extract data: Mysql_fetch_row() Mysql_fetch_assoc() Mysql_fetch_object()

1] echo " "; 2] 3] if(mysql_num_rows($result) > 0) 4] { 5]while($row = mysql_fetch_row($result)) 6]{ 7]echo " $row[1], $row[2] "; 8]} 9]} 10]echo " ";

1] echo " "; 2] 3] if(mysql_num_rows($result) > 0) 4] { 5]while($row = mysql_fetch_assoc($result)) 6]{ 7] echo " $row[‘lastname’], $row[‘firstname’] "; 8]} 9]} 10]echo " ";

1] echo " "; 2] 3] if(mysql_num_rows($result) > 0) 4] { 5]while($row = mysql_fetch_object($result)) 6]{ 7] echo " $row->lastname, $row->firstname "; 8]} 9]} 10]echo " ";

mysql_free_result($result); mysql_close($connection); ?>

<?php $connection = mysql_connect(‘localhost’,’root’,’password’); mysql_select_db('friends') ; $query = 'Select * FROM names'; $result = mysql_query($query); echo " "; if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result)) { echo " $row[1], $row[2] "; } echo " "; mysql_free_result($result); mysql_close($connection); ?>

PHP Commands mysql_connect(a,b,c ) a = dbserver b = user c = password mysql_select_db(a) a = database mysql_query(a) a = SQL command mysql_num_rows() Counts the number of rows $a=mysql_fetch_row(a)$a=mysql_fetch_assoc() $a=mysql_fetch_object()mysql_free_result(a)Mysql_close()

1 st Activity for the Semi-Finals

1.Make a Database named DB_31_[your block] 2.Make a Table named Employees Data Entity and Attributes: Idnum Lastname Firstname Department (Admin, Logistics, Sales, Accounting) Years Gender

1 st Page: The Site will Ask for the Lastname 1 st Page: The Site will Ask for the Lastname 2 nd Page: The Site will Show the Record 2 nd Page: The Site will Show the Record Does the record exist? Error Page: The Site give a feedback Error Page: The Site give a feedback False True

Show your work on next Tuesday.