Wednesday, November 29, 2006

Moved to beta.blogger

This blog has now moved to dsa2006.blogspot.com to take advantage of th enew features of beta.blogger.

Friday, November 24, 2006

Week 9 - Managing short lived data

This week we look at modelling and storing data associated with the interaction between user and machine, including the use of cookies and sessions, and finishing with Associative arrays

Friday, November 17, 2006

Sessions

One thing that you may want to do in your Flickr application is have login information available on every page of your site. There are a number of ways of doing this and Chris will cover this in next weeks lesson. For now though you might like to read this chapter from "Web Database Applications with PHP and MySQL" by David Lane that describes the different possible ways in PHP.

Week 8 - One thing in one place

This week's lecture deals with the issue of normalisation in data and code.

Thursday, November 09, 2006

Week 7 - Browser- Server interaction with PHP

The slides for this lecture describe how to use forms and sticky forms with PHP. Here are the full set of examples. Note that in this code, the parameters are referenced directly as PHP variables, rather than using the $_REQUEST array in the album code. This approach is usable but depreciated ( i.e. you are advised not to use it). Most (All?) commercial hosting sites will require the more wordy but more secure approach.


I have also adapted a tutorial from the WebMonkey site and added some advice on how to use PHP at home, paying special attention to how to secure your server which is very important.

Wednesday, November 08, 2006

Practical PHP WIKI

I've just found an excellent resource for people wanting to learn PHP - the Practical PHP WIKI. Highly recommended.

Tuesday, November 07, 2006

Coursework 1

The specification for the first coursework, a group project, is here and hard-copies were handed out in lectures some weeks ago. Groups have been created and are listed in a previous entry. Sample PHP code to demonstrate how to do the basic operations is provided, as is guidance on the use of PHP and MySQL in CEMS.

Saturday, November 04, 2006

Simple Album code

Here is a very basic photo album application implemented in PHP and MySQL with all sources in this zip file.

There is sample PHP code for doing some of the basic tasks in this application:
  • creating a member
  • editing a members details
  • adding a photograph
  • displaying photos
This implementation is very basic and you should identify shortcomings, select those that you will want to repair or new functionality to be added and then extend this base code (or write your own from scratch) .

I''ve made a few minor improvements to the sample code handed out in class:
  • A few more comments
  • Changed from $_GET[] to $_REQUEST[] as the array from which form data is accessed. This array includes data sent from a form either as method='get' or method='post'. Use get during testing and switch to post if necessary in production
  • dropped the MYSQL_ASSOC parameter - it's not necessary

PHP

PHP in CEMS

The current version in CEMS is PHP5.

There are three servers with slighly different PHP configurations.
  • www.cems.uwe.ac.uk - a PHP script will run either on web02 for students or web03 for staff. PHP on these servers has error reporting turned off. For students, www is only accessible if a request has been approved to permit access.
  • isa.cems.uwe.ac.uk - error reporting is turned on. You should use this server for all development. isa is only available within UWE
  • stocks.cems.uwe.ac.uk is an older server and runs PHP4
You can check the PHP configuration: isa, www, stocks

Hints
  • Put all php scripts in a suitable subdirectory of your public_html account on the UNIX server (in the nas folder)
  • To execute a php script, use a URL of the form
    • http:isa.uwe.ac.uk/~meonunix/DSAW1/addMember.php
  • Use the 'isa' host for all development.
  • You need a line editor like PFE32 so that when an error references a line number, you can find that line in the editor. (we need a better editor - suggestions?)
  • Beware of the slight time lag between editing a script via Windows and the same changed script being executed on the relevant UNIX server.
  • Use the $_REQUEST array to access both get and post variables. Use method="get" when testing - it's much easier to detect errors if you can see the values being passed from the browser on the command line. You can also bookmark a URL so a test can be repreated without having to enter the data again. You will also need to use 'get' when a deep link is created, for example in the Album code to fetch a a JPEG.
  • You can get a php script to display nicely using a suffix of .phps. This can help spot missing quotes or brackets. In my examples I create a symbolic link in Unix to the .php file itself. Beware of exposing passwords to your MySQL account if you do this - place connection details in a separate file which can be placed above the web accessible pages in public_html.
Links
Books
  • Larry Ullman, PHP and MySQL for Dynamic Web Sites, Peachpit Press ISBN 0321336577
  • Luke Welling and Laura Thomson, PHP and MySQL Web Development, Sams Publishing. ISBN 0672326728
  • Leon Atkinson, Core PHP Programming, Prentice Hall , 2001

MySQL

MySQL in CEMS

MySQL is installed for student use on the host 'shares', a Unix server accessible only from within the UWE domain. The current version is 4.0.13.

Each student has one database, with the same name as their UNIX username. All tables must be created in this database. Login with the UNIX username and original UNIX password. Get it reset by the help desk if you can't recall what this password is.

Access
You can access the database in either of two ways:
  • Using the web client PHPMyAdmin: http://isa.cems.uwe.ac.uk/new/phpmyadmin/
    • This GUI interface allows you to browse, edit, create and modify tables. However, since we are using QSEE to generate code, this will not be so helpful although a file of SQL commands can also be executed.
  • By logging in directly to the server for example, using Putty and starting the SQL command line interpretor (CLI).
    • e.g to start: >mysql - u cjwallac -ppasssword
    • to execute a file of SQL commands use the source command : source 'filename'
Hints
  • Table names on the version of MySQL running on the host 'shares' are case sensitive because this a Unix server. Take care when developing on Windows because case is not signicant so code may work on your own machine but not when installed at UWE.
  • The SQL generated from QSEE will cause errors when loaded using PHPMyAdmin due problems with comment lines with no space after --. You must also ensure that there is a use statement at the beginning. To overcome these problems you must edit the generated code. The mysql CLI is not so fussy and thus easier to use.
  • auto_increment is not settable in QSEE so this will need to be set separately. One approach is to define such changes in a separate file of Alter Commands for example:
    • alter table photo
      modify photoid int auto_increment;

Links