Creating Databases for Web Applications SQL Select extras Listing [names of] tables generalized display of recordset simple password handling php and other.

Slides:



Advertisements
Similar presentations
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Advertisements

Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
Web Database Programming Connecting Database to Web.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Objectives Connect to MySQL from PHP
1 Creating a Non-Conditional List A- What are you going to do? You will “list” “all of the records” in a database. (it means you will not use any condition!)
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
Creating Databases SELECT. UPDATE. Demonstrate projects. Classwork / Homework: Prepare to choose teams & projects.
Creating Databases for Web Applications Posting due by next class on project! Lab: using files & work session Class: asp Application object 3-tier, separating.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
CSCI 6962: Server-side Design and Programming
Creating databases for web applications
LIS651 lecture 7 PHP mySQL Thomas Krichel
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
Class 8Intro to Databases Authentication and Security Note: What we discuss in class today covers moderate to low security. Before you involve yourself.
1 Tutorial 2 ABC Web site. Objective Learning web applications design Conducting assumed business logic online Connecting the Database with the web pages.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
PHP – MySQL Extensions. Table used in most examples CREATE TABLE product ( rowID INT NOT NULL AUTO_INCREMENT, productid VARCHAR(8) NOT NULL, name VARCHAR(25)
Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for.
Creating Databases for Web applications Making a table of SQL queries. PHP and other DBMSs. Rights. Left Join, etc. Homework: Make posting on Open Source.
Creating databases for web applications Play quizzes Testing process regular expressions: form validation PHP coding handling forms Homework: regular expressions.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Creating Databases Uploading Files. Reading & writing files. Homework: Starting planning ‘original’ project.
Python MySQL Database Access
PHP meets MySQL.
Creating Databases for Web Applications cookie examples lab time: favorites cookies & Sessions class time for group work/questions on projects Next class:
Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
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.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Lecture 10 – MYSQL and PHP (Part 2)
Website Development with PHP and MySQL Saving Data.
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
Session 7: Getting PHP to Talk to MySQL. Objectives Connecting to the Database Building & Executing the SQL SELECT Query Fetching & Displaying the data.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
Creating Databases for web applications [Complete presentations] More SQL Class time: discuss final projects. Do posting if you have not done it.
Creating databases for web applications Library. New example: student database. Homework: Complete class example. Catch up on source postings. Do creation.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending working: both html and Flash!
Creating databases for web applications Report on using sources, getting examples working. Retrieve information from database. Recordsets. Arrays. Loops.
PHP Programming. Topics Database Handling (MySQL, MSSQL, ODBC)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
CSC 405: Web Application Engineering II Course Preliminaries Course Objectives Course Objectives Students’ Learning Outcomes Students’ Learning Outcomes.
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
CSC 2720 Building Web Applications Accessing MySQL from PHP.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Labtest.ASP Notes. INSERT STATUS INSERT STATUS
Creating Databases for Web applications Making a table of table information. Reprise on database design. SQL. Classwork/Homework: Projects! Postings.
Introduction to Dynamic Web Programming
Creating Databases Local storage. join & split
Presentation transcript:

Creating Databases for Web Applications SQL Select extras Listing [names of] tables generalized display of recordset simple password handling php and other databases Homework: work on projects, new & old posting assignments

GetImageSize example Addition to code shown last time: $size=GetImageSize($file); print ("Dimensions are: ".$size[0]." by ".$size[1]." pixels. "); $area = $size[0]*$size[1]; print ("Area is $area pixels. ");

results (first part) uploading file named jpg File size is fullname is: D:\\InetPub\\wwwroot\\users\\jeanine \\\91940.jpg. Dimensions are: 600 by 393 pixels. Area is pixels. file successfully uploaded.

Select operators =, >, =, < IS NOT NULL, IS NULL BETWEEN IN, NOT IN LIKE (has wild card character: %, others) REGEXP Also, have DISTINCT SELECT DISTINCT category FROM questions;

Select aggregate functions AVG, COUNT, MIN, MAX, STD, SUM SELECT AVG(score) in players; SELECT COUNT(*) in players WHERE score > 100; Get these as 0 th field, 0 th row of recordset SELECT AVG(score), MIN(score), MAX(score), STD(score), COUNT(score) in players; Get these as 0 th, 1 st, 2 nd, 3 rd, 4 th, 5 th fields of 0 th row of recordset

Select control grouping SELECT order_id, SUM(quantity) FROM ordereditems GROUP BY order_id; limit: SELECT product_id, quantity FROM ordereditems LIMIT 10; limit: starting from 1 st record fitting conditions and returning 10 records SELECT product_name, product_description, product_cost FROM catalog LIMIT 1, 10; For paging, repeat with variables indicating 1 st and last entries: "SELECT product_name, product_description, product_cost FROM catalog LIMIT $FIRST, 10"

SELECT order_id, SUM(quantity) FROM ordereditems GROUP BY order_id; Query result: Original data

What are tables in given database Show table names <?php require("jeanine\quizphp\opendbq.php"); $query="show tables"; $rs=mysql_db_query($DBname, $query, $link); ?> Table names <? while ($row=mysql_fetch_array($rs)){ print(" "); print($row[0]); print(" "); } print(" "); ?>

result Table names catalog customers history ordereditems orders players questions

Show table names and field names <?php require("jeanine\quizphp\opendbq.php"); $query="show tables"; $rs=mysql_db_query($DBname, $query, $link); ?> Table names <? $i = 0; while ($row=mysql_fetch_array($rs)){ print(" "); $tablenames[$i] = $row[0]; $i++; print($row[0]); print(" "); } print(" ");

for ($j=0;$j<$i;$j++) { $query = "describe ".$tablenames[$j]; print (" ". $tablenames[$j]. " table \n "); print (" Field Type Null Key \n "); $rt=mysql_db_query($DBname,$query,$link); while ($fi=mysql_fetch_array($rt)) { print (" ". $fi['Field']. " \n "); print (" ".$fi['Type']. " \n "); print (" ".$fi['Null']. " \n "); print (" ".$fi['Key']. " \n "); print (" "); } print (" "); } ?>

Table of queries If you have a large set of fixed SQL queries, you may make a new table: iddescriptiontext 1final diagnosis when presenting signs of appendicitis Select final.diagnosis from final, initial where initial.temp > 100 AND initial.pain = 'left' AND final.caseno = initial.caseno 2initial potential ulcer casesSelect * from initial where initial.pain = 'sharp' AND initial.temp < 100 ….

Present to user Pick selection: description final diagnosis when presenting signs of appendicitis initial potential ulcer cases Don't show the user the messy SQL

Produce responses Make the query the SQL corresponding to the user's choice. Display recordset in a table –Now, need generalized code that creates headings for tables and extracts names of fields 'on the fly' based on information in recordset. php: –mysql_fetch_field –mysql_fetch_array

Current Favorites <?php require("openfirstdb.php"); $query="Select * from favorites"; $result=mysql_db_query($DBname, $query, $link); $fieldnames= Array(); print (" "); $nf = mysql_num_fields($result); for ($i=0; $i<$nf;$i++) { $fieldobj= mysql_fetch_field($result); $fieldnames[$i]=$fieldobj->name; print (" ".$fieldnames[$i]." "); } print (" \n"); while ($row=mysql_fetch_array($result)) { print (" "); for ($i=0; $i<$nf; $i++) { print (" ".$row[$fieldnames[$i]]." "); } print(" "); } mysql_close($link); ?> first for loop to set up headers Second for loop, in while loop, to extract field data.

asp version recordset.fields.count recordset.fields(i).Name

Input and submit questions to quizasp db <% var sq ="SELECT * from favorites"; rs=Server.CreateObject("ADODB.RecordSet"); rs.Open (sq,Conn, 1,3); var fieldnames= new Array(); Response.Write (" "); var nf = rs.fields.count; var nr=rs.RecordCount; for (i=0; i<nf; i++) { fieldnames[i]=rs.fields(i).Name; Response.Write(" "+ fieldnames[i] +" "); } Response.Write (" \n"); while(!rs.EOF) { Response.Write(" "); for (j=0; j<nf; j++) { Response.Write (" "+rs.fields.item(fieldnames[j])+" "); } Response.Write(" "); rs.move(1); } %>

Authentication using passwords Technique is to establish a table of stored user names and encrypted passwords one way encrpytion –php's crypt or MySql's password use SQL statement that counts the number of records with the pair of values. If count is greater than 0, then the person is accepted. Use session variables or cookies to check that user is 'authenticated'. Separate procedure for storing values.

php: crypt Can be used with or without a seed: $cipher = crypt($password,$seed); You need to make sure that the seed is the same!

SQL $query = "Select count(*) from passtable where name = '$user' and pass = '$cypher'"; $result=mysql_query($Dbname,$query); $count = mysql_result($result,0,0); if ($count>0) { ….okay} else { …. no good } calculated value. recordset has one row, one field

php and other databases php and MySQL have a special set of functions. There are also special sets for some other databases. –show some Oracle code Alternative is to use a general API (application programming interface). –ODBC: open database connectivity –ADODB: active data object data base –?

<?php PutEnv("ORACLE_SID=ORASID"); $connection = Ora_Logon ("username","password"); if ($connection == false){ echo Ora_ErrorCode($connection).": ".Ora_Error($connection)." "; exit; } $cursor = Ora_Open ($connection); if ($cursor == false){ echo Ora_ErrorCode($connection).": ".Ora_Error($connection)." "; exit; } $query = "select * from _info"; $result = Ora_Parse ($cursor, $query); if ($result == false){ echo Ora_ErrorCode($cursor).": ".Ora_Error($cursor)." "; exit; }

$result = Ora_Exec ($cursor); if ($result == false){ echo Ora_ErrorCode($cursor).": ".Ora_Error($cursor)." "; exit; } echo " "; echo " Full Name Address "; while (Ora_Fetch_Into ($cursor, &$values)){ $name = $values[0]; $ = $values[1]; echo " $name $ "; } echo " "; Ora_Close ($cursor); Ora_Logoff ($connection); ?>

ODBC $connect = odbc_connect("firstdb", "", ""); // no user, no password $query = "SELECT title, description FROM favorites"; $result = odbc_exec($connect, $query); print (" \n"); while(odbc_fetch_row($result)){ print (" "); print(odbc_result($result, 1)." "); print (odbc_result($result, 2)." "); } print (" ");odbc_close($connect); DSN Index starts at 1

ADODB <? include('adodb.inc.php'); $conn = &ADONewConnection('access'); $conn->PConnect('firstdb'); $query = "Select title, description from favorites"; $recordSet = &$conn->Execute($query); while (!$recordSet->EOF) { print $recordSet->fields[0].' '.$recordSet->fields[1].' '; $recordSet->MoveNext(); } $recordSet->Close(); $conn->Close(); ?> ADODB needs to be installed Note -> syntax Note & syntax

ADODB functions Metatypes for handling different names for types (char versus string, others) functions for handling dates debugging help Source:

Homework Post constructive comments on other projects (as a reply to posting announcing project). Post comments on php versus asp/JavaScript, MySql versus Access, Open Source versus proprietary/Microsoft. Finish* projects.