Top Banner
DataBase course notes 07 DataBases php + MySQL 1
41

DataBase course notes 07 DataBases php + MySQL 1.

Jan 02, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • DataBase course notes 07DataBasesphp + MySQL*

    DataBase course notes 07

  • Pizza delivery exampleusers, cart, detail, statuspizza

    user can be power user update pizza

  • MySQL DataBase diagram

  • four basic functions - CRUDCreateRead / RetrieveUpdateDelete

    DataBase course notes 07*

    DataBase course notes 07

  • Images, database or filesystemoptions when you want to store imagesstore data in your databaseblobstore data on filesystemextra information about fileDataBase course notes 07*

    DataBase course notes 07

  • AdvantageFilesystem over Databasefile operations perform faster since these are low-level OS functions easier to replicate files onto other serversdatabase will not be bloated by extremely large files large files may slow down other connectionsDatabase over Filesystemall file data is stored in single location back up your images in single locationfilesystem you may lose file that have database record pointing to itopposite may also happen (have file without corresponding record)

    DataBase course notes 07*

    DataBase course notes 07

  • Two examples, Pizza 1 & 1Pizza1CRUD only for pizza table in this examplestoring images in filesystemin folder images same files in Pizza 1 & 2Pizza2CRUD only for pizza table in this examplestoring images in database

    same files in Pizza 1 & 2

    DataBase course notes 07*

    DataBase course notes 07

  • PizzaExpres_Functions.php

  • C Retrieve UDDataBase course notes 07*

    DataBase course notes 07

  • Pizzas.php

    Pizza Expres - PIZZAs

  • Pizzas.php$sqlQ = "SELECT Pizza_ID, PizzaName FROM Pizza ORDER BY PRICE ASC";$result = mysql_query($sqlQ);print("");$numRows = mysql_num_rows($result);$colNo = 2;$crtColNo = 1;for ($i = 1; $i
  • Pizzas.phpfor ($i = 1; $i
  • Pizzas.phpfor ($i = 1; $i
  • Pizzas.phpDataBase course notes 07*

    DataBase course notes 07

  • Pizzas.php

    Pizza Expres - PIZZAs

    PIZZA MARGHERITA 32cm

    New PIZZA PROSCIUTTO FUN32cm

    PIZZA PROSCIUTTO E FUNGHI 32cm

    PIZZA HAWAI 32cm

    DataBase course notes 07*

    DataBase course notes 07

  • pizza_detail.php ? Pizza_ID = 1DataBase course notes 07*

    DataBase course notes 07

  • pizza_detail.php ? Pizza_ID = 1Pizza Expres - PIZZA Details

    PIZZA MARGHERITA 32cm13 Sos de Rosii, Mozzarella, Busuioc - are un blat subtire cu un excelent sos din pulpa de rosii preparat special dupa o reteta originala

    Pizza1 image stored in filesystem

    DataBase course notes 07*

    DataBase course notes 07

  • pizza_detail.phpinclude "PizzaExpres_Functions.php";connectDB();$vPizza_ID = $_GET['Pizza_ID'];$sqlQ = sprintf("SELECT Pizza_ID, PizzaName, Detail, Price, Image FROM Pizza WHERE Pizza_ID = '%d' ;",$vPizza_ID);$result = mysql_query($sqlQ);DataBase course notes 07*

    DataBase course notes 07

  • pizza_detail.phpprint("\n");$crtRow = mysql_fetch_array($result);$vPizzaName = $crtRow["PizzaName"];$vDetail = $crtRow["Detail"]; $vPrice = $crtRow["Price"]; $vImage = $crtRow["Image"];Pizza1 image stored in filesystem in database stored character string with file nameDataBase course notes 07*

    DataBase course notes 07

  • pizza_detail.phpprint("");print(" $vPizzaName$vPrice");$vImage2 = "./Images/" . $vImage;print " ";print("\n $vDetail");print("");print("");DataBase course notes 07*

    DataBase course notes 07

  • login.php

    Pizza Expres LogIn

    Login name:

  • Create R Update DeleteNot particularly happy with the solution but in a hurry I just want to show examples of CRUD operationspaint a menu to chooseCreate InsertUpdate UpdateDelete Deleteonly Power Users have access to CRUD operations on pizza tableDataBase course notes 07*

    DataBase course notes 07

  • login.php

    Password:

  • login_action.php
  • login_action.phpif ($Nr 1)print("Error: Non Power User!");if ($oInsert && ($Nr == 1))header("Location: http://localhost/PizzaExpres/ins.php");if ($oUpdate && ($Nr == 1))header("Location: http://localhost/PizzaExpres/up.php");if ($oDelete && ($Nr == 1))header("Location: http://localhost/PizzaExpres/del.php");

    ?>

  • Insert - ins.php

    Pizza Expres - INSERT

  • Insert - ins.php// **************************************************// main page here:include "PizzaExpres_Functions.php";connectDB();

    if($ins) {

    ?>

  • Insert - ins.phpif($ins) {$vPizzaName = $_POST["PizzaName"];$vDetail = $_POST["Detail"];$vPrice = (real)$_POST["Price"]; move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'],"c:/tmp/latest.img");$instr = fopen("c:/tmp/latest.img","rb");$vImage = addslashes(fread($instr,filesize("c:/tmp/latest.img"))); }

  • if($ins) {$vError = validIns($vPizzaName, $vDetail, $vPrice, $vImage);if ($vError == "") {$insError = insertIns($vPizzaName, $vDetail, $vPrice, $vImage);if ($insError == 0) {print("Pizza was Inserted in database!");print("INSert");} else {print("Unexpected Error when Trying to Insert Pizza in database!");}} else {paintIns($vPizzaName, $vDetail, $vPrice, $vImage, $vError);}} else { paintIns("","",0,"","");}

  • Update up.php

  • Delete del.php

  • Programming AssignmentDataBase Application (any database appl. will work)expect your work at E-Mail addressCalin.Cenan @ cs.utcluj.roplease state your name and group in your mail especially if your mail address instead of Name@somewhere is something like Shmecherul DataBase course notes 07*

    DataBase course notes 07

  • Programming AssignmentI will expect for programming assignment written in php with MySQL databasetell me if you expect from me something different that:

    for example check URLI must have access to database

    DataBase course notes 07*

    DataBase course notes 07

  • Programming Assignmentlook for something.sql Create Database somethingExecute SQL file (create database, populate database)look for some folderMove folder in www, look to execute something index.php, .

    DataBase course notes 07*

    DataBase course notes 07

  • Programming AssignmentI will asses mainly the databaseexpect around ten tables in the databasethere is no database whiteout data expect around ten rows of in each tableexpect to see some views in the databasedata should be readable or better credible, for example book author could beQwerty, or abc un readable, unacceptableNicolae Guta readable but not credibleDataBase course notes 07*

    DataBase course notes 07

  • Programming AssignmentI will asses mainly the functionalityFancy web design, as Ian Flemings James Bond says is For Your Eyes OnlyExpect mainly presentation viewpresentations pages with content obtained from database, search, filter, categories, Expect at least 1 table at most 2-3 table with update operationsregister user, CRUD for main products,

    DataBase course notes 07*

    DataBase course notes 07

  • Programming AssignmentCannot trick me on number of tablesComputers have motherboards, memories, video boardsEach have their own characteristicsComputer table is related to Motherboards table, Memories table, Video Boards tableCount 1 table not 4 tablesDataBase course notes 07*

    DataBase course notes 07

  • Programming AssignmentAll names should be one single languagepreferable english

    DataBase course notes 07*

    DataBase course notes 07

  • Programming Assignment -example of acceptable domainsE-Commerce amazon, tennis-warehouse, eMag, GSM, .Movies, musicReal-estateCar RentalAir ticket reservation

    DataBase course notes 07*

    DataBase course notes 07

  • Programming Assignment -debatable? domainsMMORPGdont have expertise (in gamming other then Tetris and Pac-man) to asses if the database and application is correcthave to accept everything students saydatabase application it is exactly what is needed only these 2-3 table model the domain

    DataBase course notes 07*

    DataBase course notes 07

  • BackUp and Restore workDevPHP (IDE, editor HTMP, php)mowes (apache web server, support php, MySQL database server)MySQL Workbench front-end tool for DB200 Mb portablecode folder in wwwdatabase folder in data DataBase course notes 07*

    DataBase course notes 07