Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.

Slides:



Advertisements
Similar presentations
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Advertisements

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.
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.
Introduction to Structured Query Language (SQL)
Objectives Connect to MySQL from PHP
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
MIS Week 11 Site:
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.
ASP.NET Programming with C# and SQL Server First Edition
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Class #2: Introduction to MySQL (Continued) Where clause (continued) Aggregate Functions Creating users Backing up your database Indexes (if time) Importing.
Creating Databases with MySQL Workbench Build the Forums database in Ullman’s Chapter 6.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
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.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Database: SQL and MySQL
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
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.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 10: Distributed Databases Jerry Post Copyright © 2003.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 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.
3 A Guide to MySQL.
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.
Databases.
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
Open Source Server Side Scripting Permissions & Users
Introduction to Web programming
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
Tutorial 6 PHP & MySQL Li Xu
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
SQL Basics BCHB697.
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
Introduction to Web programming
Presentation transcript:

Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data

Open Source Server Side Scripting 2 ECA 236 sitename table users user_idMEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY first_nameVARCHAR(15) NOT NULL last_nameVARCHAR(30) NOT NULL VARCHAR(40) passwordCHAR(16) NOT NULL registration_dateDATETIME NOT NULL

Open Source Server Side Scripting 3 ECA 236 INSERT  1 st way to INSERT data:  specify the columns to be used  syntax:  using this way, you can add rows of records, but populate only the fields you want  unspecified columns will be treated as NULL or given a default value INSERT INTO tablename (column1, column2, column5 ) VALUES( ‘value1’, ‘value2’, ‘value5’ );

Open Source Server Side Scripting 4 ECA 236 INSERT cont …  2 nd way to INSERT data:  do not specify columns  syntax:  using this way, you include a value for every column, even if NULL  failure to match number of values to number of columns will generate an error INSERT INTO tablename VALUES ( ‘value1’, NULL, ‘value3’ );

Open Source Server Side Scripting 5 ECA 236 INSERT cont …  2 nd way to INSERT data:  to insert multiple rows, separate each record with a comma  syntax: INSERT INTO tablename VALUES ( ‘value1’, NULL, ‘value3’ ), ( ‘value4’, NULL, ‘value6’ ), ( ‘value7’, NULL, ‘value9’ ) ;

Open Source Server Side Scripting 6 ECA 236 NOW( )  NOW( ) is a MySQL function  use NOW( ) with date data types  NOW( ) inserts the current date and time into a column  do not put a space between the function name and the parentheses

Open Source Server Side Scripting 7 ECA 236 inserting data into users  to insert a new row into the users table:  use the NOW( ) function to insert the current date information  notice that NOW( ) is not enclosed in quotes INSERT INTO users (first_name, last_name, , password, registration_date) VALUES ('John', 'Lennon', PASSWORD('Happin3ss'), NOW( ));

Open Source Server Side Scripting 8 ECA 236 inserting data into users cont …  we left out the user_id column  user_id will be set to NULL  because user_id is AUTO_INCREMENT, MySQL will set the value to the next logical number INSERT INTO users (first_name, last_name, , password, registration_date) VALUES ('John', 'Lennon', PASSWORD('Happin3ss'), NOW( ));

Open Source Server Side Scripting 9 ECA 236 inserting data into users  to INSERT several more records: INSERT INTO users (first_name, last_name, , password, registration_date) VALUES ('Paul', 'McCartney', PASSWORD('letITbe'), NOW( )), ('George', 'Harrison', ', PASSWORD('something'), NOW( )), ('Ringo', 'Starr', PASSWORD('thisboy'), NOW( ));

Open Source Server Side Scripting 10 ECA 236 inserting data into users  when using INSERT enclose strings with single quotes  do not quote numbers or function calls  to INSERT a value that contains a single quote, escape the quote with a backslash

Open Source Server Side Scripting 11 ECA 236 loading text files into tables  in some situations you may have to change the configuration of the my.ini file  modify my.ini file, usually located in Windows or WINNT directory  add the following code to the [mysqld] section [mysqld] set-variable=local-infile=0

Open Source Server Side Scripting 12 ECA 236 loading text files into tables cont …  text files should contain:  one row for each record to be loaded  each column separated with a delimiter  you can specify delimiter and end of line marker  by default, MySQL uses a tab and linefeed  NULL values may be represented with \N tabs first_name last_name password

Open Source Server Side Scripting 13 ECA 236 loading text files into tables cont …  LOAD DATA INFILE  loads a text file into a table  for more information visit the MySQL Manual:  Loading Data into a Table  Security issues with LOAD DATA LOCAL  LOAD DATA INFILE Syntax LOAD DATA INFILE “path_to/file_name.txt” INTO TABLE table_name;

Open Source Server Side Scripting 14 ECA 236 loading text files into tables cont …  EXERCISE  download users_data.txt from web site  create a folder one level down from C: named data  save users_data.txt  in mysql monitor:  view table after data has loaded LOAD DATA INFILE “c:/data/users_data.txt” INTO TABLE users; SELECT * FROM users;

Open Source Server Side Scripting 15 ECA 236 SELECT … INTO OUTFILE  complements LOAD DATA INFILE  write data from a database to a file  defaults: >writes tabs between fields >writes newlines at end of lines  when working on Windows, escape backslash SELECT * INTO OUTFILE ‘c:\\data\\into_outfile.txt’ FROM users;

Open Source Server Side Scripting 16 ECA 236 UPDATE  UPDATE allows you to modify existing records  syntax:  UPDATE multiple columns by separating with comma  use a WHERE clause to identify rows to UPDATE UPDATE table_name SET column = ‘value’; UPDATE table_name SET column1 = ‘value1’, column2 = ‘value2’; UPDATE table_name SET column3 = ‘value’ WHERE column1 = ‘value1’;

Open Source Server Side Scripting 17 ECA 236 UPDATE cont …  the users table contains unencrypted passwords  use PASSWORD( ) function to encrypt current unencrypted values in password column  notice there are not quotes around password being passed to PASSWORD( ) UPDATE users SET password = PASSWORD(password) WHERE user_id >= 5;

Open Source Server Side Scripting 18 ECA 236 UPDATE cont …  registration_date has been set to zero for all new entries  use the WHERE clause to affect only those rows with a registration_date set to zero UPDATE users SET registration_date = NOW( ) WHERE registration_date = 0;

Open Source Server Side Scripting 19 ECA 236 LOCAL  LOAD DATA LOCAL INFILE  if the LOCAL keyword is included the file is read by the client program on the client machine, and sent to the server  if the LOCAL keyword is not included the file must be located on the server  files to be loaded must be readable by all

Open Source Server Side Scripting 20 ECA 236 backing up a database  mysqldump  will back up tables and their structure  run directly from command line  dump file to the screen: mysqldump -u root -p sitename

Open Source Server Side Scripting 21 ECA 236 backing up a database cont …  mysqldump  create an output file  contains SQL commands to create the table  contains data to populate the table mysqldump -u root -p sitename > c:/data/mydump.sql

Open Source Server Side Scripting 22 ECA 236 backing up a database cont …  mysqldump  read the file back into MySQL using the syntax:  review MySQL Manual for a long list of options to use with mysqldump mysql -u root -p sitename < c:/data/mydump.sql

Open Source Server Side Scripting 23 ECA 236 source  to run MySQL statements stored in a text file  use source or \.  takes the filename as an argument  do not use quotes or semicolon \. C:/data/insert_record.sql source path_to/file_name.txt \. path_to/file_name.txt