PHP-language, files Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management

Slides:



Advertisements
Similar presentations
Development of Web Applications - Contents Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management.
Advertisements

V 1.0 OE NIK 2013 PHP+SQL 4. File handling basics File-based "database" File-based guestbook 1.
More on PHP Coding Lab no. 6 Advance Database Management System.
Facebook Applications and Marketing Teppo Räisänen
Chapter 7 Data Management. Agenda Database concept Import data Input and edit data Sort data Function Filter data Create range name Calculate subtotal.
Pasewark & Pasewark 1 Access Lesson 6 Integrating Access Microsoft Office 2007: Introductory.
OULU ADVANCED RESEARCH ON SOFTWARE AND INFORMATION SYSTEMS Teppo Räisänen | Oulu University of Applied Sciences Facebook programming Teppo Räisänen
Intermediate PHP (2) File Input/Output & User Defined Functions.
Development of Web Applications - Introduction Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information.
I-SUITE 101. I-SUITE BASICS Install I-Suite Server Clients Setup Initial Admin User Create Database Add Users Create Additional Admin User Create I-Suite.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
VT SMS System User Manual
Week Three CIT 354 Internet II. 2 Objectives Displaying Dynamic Content Sending Using Your File System Common Programming Errors Summary Quiz,
Lecture 06 – Reading and Writing Text Files.  At the end of this lecture, students should be able to:  Read text files  Write text files  Example.
Web Programming with PHP (2). PHP Scripts o every PHP script is a collection of one or more statements; these statements appear as a collection of names,
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data.
Website Development with PHP and MySQL Saving Data.
Teppo Räisänen School of Business and Information Management Oulu University of Applied Sciences.
Chapter 17 Creating a Database.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
PHP-language, conditional statements Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management.
More PHP…. Understanding Variable Scope The term scope refers to the places within a script where a particular variable is visible. The six basic scope.
1 Chapter 7 – Object-Oriented Programming and File Handling spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
Storing and Retrieving Data
12 steps for Mail Merge Setup Mpact Magic. Step 1 Open Your MS Outlook program and put it an offline mode. Go to Main Menu >> File >> Work Offline.
Introduction to File Processing with PHP - Part 2 Indexed Files.
Outline Overview Opening a file How to create a file ? Closing a File Check End-of-file Reading a File Line by Line Reading a File Character by Character.
PHP Programming.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
EGR 115 Introduction to Computing for Engineers Formatted File Input / Output Wednesday 12 Nov 2014 EGR 115 Introduction to Computing for Engineers.
Files Tutor: You will need ….
PHP-language Variables, assingment and arithmetic operations Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and.
PHP-language, sessions Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management
Producing a Mail Merged Letter Step 1 Create an Access database for Names and Addresses you can use the ‘Customers’ template in Group Work. Enter the necessary.
Lecture 7 Conditional Scripting and Importing/Exporting.
CSV Files Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Files A collection of related data treated as a unit. Two types Text
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
PHP-language, loops Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management
Connecting to Files In order to read or write to a file, we need to make a connection to it. There are several functions for doing this. fopen() – makes.
Introduction to File Processing with PHP. Review of Course Outcomes 1. Implement file reading and writing programs using PHP. 2. Identify file access.
When you open Access you can open or import an existing.csv file. Check that it recognises that the fields are separated by commas.
PHP-language, database- programming Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
GNG1106 Lab # 8 C Structures and Files Slides by: Mohamad Eid Contributors: Diana Inkpen, Alan Williams, Daniel Amyot.
Chapter 6 Persistence-Saving and Retrieving Data
Creates the file on disk and opens it for writing
File Access (7.5) CSE 2031 Fall July 2018.
PHP-language, files Jouni Juntunen Oulu University of Applied Sciences
Performance and User Experience Improvements to the ASU/NASA Space Grant Website
File Input/Output.
File I/O We are used to reading from and writing to the terminal:
C Programming Lecture-15 File I/O
In Class Program: Today in History
User Manual KC SMS System User Manual
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
Style guidelines Teppo Räisänen School of Information and Management
Creates the file on disk and opens it for writing
Fundamentals of Data Structures
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Files Handling In today’s lesson we will look at:
Working With Databases
PHP: Hypertext Preprocessor
Lecture 6: Processing Forms with PHP
EECE.2160 ECE Application Programming
File I/O We are used to reading from and writing to the terminal:
Presentation transcript:

PHP-language, files Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management

Why files? To store data Simple to use No database available When storing complex data - use database

Basic steps using files from application 1.Open file 2.(Lock file while reading) 3.Read from/write to file 4.(Release locking) 5.Close file

Opening file Usually it is wise that applications don’t create file (necessary files are created manually during application setup) Files must be NEVER stored under public_html

fopen() $filehandle=fopen(”../somefile.csv”,”w”); … Opening modes r=read w=write a=append Check for more modes on PHP-manual

fwrite() $filehandle=fopen(”../somefile.csv”,”w”); flock($filehandle,LOCK_EX); fwrite($filehandle,”Content to be added to file.”); flock($filehandle,LOCK_UN); fclose($filehandle);

Reading a file <?php $filehandle=fopen(”…/../data.csv”,”r”); while (!feof($filehandle)) //Check if we have reached end of file { $row=fgets($filehandle); //Read current row from file print ”$row ”; //Print row without any formatting } fclose($filehandle); ?> Note that $row=fread($filehandle, 1024) works also

fclose() $filehandle=fopen(”../somefile.csv”,”r”); fclose($filehandle); You’ll have to ALWAYS remember to close to used file!

Using files in Applications Data is stored to file using e.g. delimeter character For example csv-file (Comma separated value)

Exercise Implement simple guestbook which stores messages to csv-file