PHP1-1 PHP & SQL Xingquan (Hill) Zhu

Slides:



Advertisements
Similar presentations
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Advertisements

NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
Objectives Connect to MySQL from PHP
MySQL and PHP By Trevor Adams.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
MySql In Action Step by step method to create your own database.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
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.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
In the next lectures you will learn  What is SQL  How to access mySQL database  How to create a basic mySQL database  How to use some basic queries.
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.
Python MySQL Database Access
PHP meets MySQL.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
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.
MySQL PHP Web Technology. Logging in to Command Line Start -> Programs -> AppServ -> MySQL Command Line Client Enter Password, then you’ll be working.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
CSC 2720 Building Web Applications Database and SQL.
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.
Using Special Operators (LIKE and IN)
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
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.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
 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.
Web Systems & Technologies
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
Introduction to Web programming
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
PHP and MySQL.
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Introduction to Web programming
Conection
Presentation transcript:

PHP1-1 PHP & SQL Xingquan (Hill) Zhu

PHP1-2 PHP&SQL  Relational Database systems  Structured Query Language: SQL  Access MySQL on Pluto server  Create table, add records, query, and delete records  PHP MySQL database access  Connect to MySQL server  Select database  Query  Show the results

PHP1-3 Relational database systems  A collection of tables of data  Each table can have any number of rows and columns of data  The columns of a table are named Attributes  Each row usually contains a value for each column  Rows of a table are often referred to as entries  Primary keys One column which uniquely identify the rows of the table  Both data values and primary key values in a table are called field IDFirst_nameLast_NameLobsterCrabAppleOrangeComments 1HillZhu2120Good 2HillFord1200Good 3FordJames0011Super

PHP1-4 Structured Query Language: SQL  Language for specifying access and modification to relational database  Different from most programming language  More like a structure form of English  Reserved words are not case sensitive  SELECT and select are equivalent  The whitespace separating reserved words and clauses is ignored  Commands can be spread across several lines  Simple SQL process  Create database  Use database  Create table  Add records  Search records

PHP1-5 Access SQL on Pluto  Download putty (  Download -> putty.exe -> open

PHP1-6 Access SQL on Pluto Your fau ID Username: Your fau ID Password: Your fau ID

PHP1-7 Access SQL on Pluto Your FAU ID again MySql version

PHP1-8 You are not able to create a database on Pluto, but select your own database  Use YourFAUID;  You are only able to use your own db, TSG created for you

PHP1-9 Create a table  create table orderTbl(ID int not null primary key auto_increment, first_name varchar(30), last_name varchar(30), lobster int, crab int, apple int, orange int, comments varchar(30)); Table name, you name it

PHP1-10 Insert Records  Insert into orderTbl(ID, first_name, last_name, lobster, crab, apple, orange, comments) values (1, “Hill”, “Zhu”, 2, 1, 2, 0, “Good”);

PHP1-11 Query the database  List all the records  Select * from orderTbl;

PHP1-12 Query the database  Select first_name, last_name from orderTbl;

PHP1-13 Query the database  Select * from orderTbl where first_name=“Hill”;

PHP1-14 Delete records  Delete from table where xx=y  Delete from orderTbl where last_name=“Ford”;

PHP1-15 PHP&SQL  Relational Database systems  Structured Query Language: SQL  Access MySQL on Pluto server  Create table, add records, query, and delete records  PHP MySQL database access  Connect to MySQL server  Select database  Query  Show the results

PHP1-16 An Important Step  Login into pluto mySQL server  Execute the following command  SET PASSWORD FOR = OLD_PASSWORD(‘yourfauid’);  Otherwise, you will not be able to connect to mySQL server  Error message “Client does not support authentication protocol ”  Some sort of protocol problem

PHP1-17 Php connect to MySQL server  Connect to a MySQL server  $db = mysql_connect($hostname, $username, $userpasswd);  Select database  $er = mysql_select_db("customer", $db);  $hostname="localhost";  $username="hill";  $userpasswd="hill";  $db = mysql_connect($hostname, $username, $userpasswd);  if (!$db)  {  print ("Error - Could not connect to MySQL");  exit;  } Database.php It’s YourFauId if use pluto

PHP1-18 PHP SQL Query  $qresult = mysql_query($query);  The query string should not end with a semicolon.  Return “false” on error  Return a complex “resource” structure on success  $num_rows = mysql_num_rows($qresult);  $num_fields = mysql_num_fields($qresult);  $row = mysql_fetch_array($qresult);

PHP1-19 PHP SQL Query  $row = mysql_fetch_array($qresult);  Calling Mysql_fetch_array() each time will return one row of the retrieved records (from the top to the bottom)  $row is a special array  It has two elements for each field  The first element consists of the system assigned key (0, 1, 2…) along with the field value  The second element uses attribute name as the key (“first_name”…), along with the field value  So you can use either of the following forms $row[0], $row[1]…. $row[“first_name”], $row[“last_name”]….

PHP1-20 PHP SQL Query  A simple PHP query example Customer.htmlaccesscustomer.php

PHP1-21 PHP Insert A record  $sqlquery = INSERT INTO $table VALUES($id, $first_name, $last_name, $lobval, $crbval, $appval, $orgval,$comments);  Insert order information into the database Formselection.phpFormselection.php formcheckout.phpformcheckout.php formprocesswithDB.php mysqlDBProcess.inc

PHP1-22 PHP&SQL  Relational Database systems  Structured Query Language: SQL  Access MySQL on Pluto server  Create table, add records, query, and delete records  PHP MySQL database access  Connect to MySQL server  Select database  Query  Show the results