Server-side Cheat Sheet

Reviews
Shared by: armani11
Stats
views:
37
rating:
not rated
reviews:
0
posted:
11/9/2008
language:
pages:
0
Server-side Reference Sheet Updated 22nd February 2006 This document is designed for people who understand the concept behind server-side coding, but may have difficulty remembering the exact syntax. It may also help those who understand one of the languages below in translating their ideas to another language. Code Description Tags Code Type Tags ASP <% commands %> <%= expression %> ‘ comment Response.Write(expression) PHP Java Servlets/JSP <% commands %> <%= expression %> <%! declaration %> <%@ directive %> // comment <%-- comment --> out.println(expression); request.getParameter("variableName") // comment /* comment */ echo expression; Comments Write to page Use ‘GET’ method variable (from querystring) Command Command Expression Request.QueryString("variableName") $_GET[variableName] Use ‘POST’ method variable Creating/Editing Session variables Reading Session variables Redirect to another page Include code from another file Expression Request.Form("variableName") $_POST[variableName] $_SESSION[variableName] = value; $_SESSION[variableName] header(“location: url”); exit; include(“filename”); request.getParameter("variableName") session.setAttribute(“variableName”, value); Command Session("variableName") = value Expression Session("variableName") session.getAttribute("theName") response.setHeader(“Refresh”, “time; URL=url”); <%@ include file="filename" %> Command Command Response.Redirect("url") These tags are important! For the most updated version of this document, visit http://www.tomturton.com/tutorials/ Structured Query Language (SQL) SQL is the standard language used to communicate with a database in order to read or change it. Below are only a few of the most common commands used to talk to a database. For more, check out http://dev.mysql.com/doc/refman/5.0/en/ Basic reading information from a database SELECT [WHERE [ORDER [LIMIT column(s) FROM table(s) condition(s)] BY column(s) [DESC]] offset, rows] …if multiple values, separate with commas. Use * for all columns. …strings in single quotes, operators such as =, >, <=, != etc. …DESC means descending order. …offset is the starting position, rows is number of records to display. Examples: • SELECT Writer, Director FROM Films WHERE Star = ‘Harrison Ford’ • SELECT * FROM Phones WHERE Memory >= 128 AND Make = ‘Nokia’ ORDER BY Price • SELECT * FROM Heroes ORDER BY Strength DESC LIMIT 10,5 Adding records to a database INSERT INTO table (column(s)) VALUES (value(s)) …separate columns with commas …strings in single quotes, comma separated Examples: • INSERT INTO Films (FilmID, Title, Director, Star, Year) VALUES (‘NULL’, ‘Hook’, ‘Spielberg’, ‘Robin Williams’, 1991) • INSERT INTO Phones (Make, Model, Memory, Network) VALUES (‘Sony Ericsson’, ‘K750i’, 64, ‘O2’) • INSERT INTO Heroes (Name, Location, Strength, Special Power) VALUES (‘Spiderman’, ‘New York’, 32, ‘Spider-Sense’) For the most updated version of this document, visit http://www.tomturton.com/tutorials/ Modifying records in a database UPDATE table SET column1=value1, column2=value2 [WHERE condition(s)] …comma separated expressions …no comma at the end …to limit the records to alter Examples: • UPDATE Films SET Writer = ‘Tolkien’ WHERE Saga = ‘Lord of the Rings’ • UPDATE Phones SET Network = ‘Orange’, Price = 120 WHERE Make = ‘Motorola’ AND Model = ‘L7’ • UPDATE Heroes SET Weakness = ‘Kryptonite’, Strength = 190, Location = ‘Metropolis’ WHERE AlterEgo = ‘Clark Kent’ Removing records from a database DELETE [WHERE [ORDER [LIMIT FROM table condition(s)] BY column [DESC]] rows] …only really useful with LIMIT …where rows is the number of records to remove Examples: • DELETE FROM Films WHERE Star = ‘Ben Affleck’ • DELETE FROM Phones WHERE Price > 240 OR Make = ‘Own Brand’ • DELETE FROM Heroes WHERE Status = ‘deceased’ ORDER BY Strength LIMIT 12 I haven’t covered commands to create a database or add tables. I use the fantastic open-source phpMyAdmin to do this for me, but you will need SQL to query the database from within your server-side code. Special thanks to Martin Beck and Simon Grout for reviewing this document

Related docs
Introduction to Server Side Emulation
Views: 59  |  Downloads: 5
Footprinting_ Server Side Scripring_ Mandrake
Views: 4  |  Downloads: 0
Cascade Server Mini Cheat-Sheet
Views: 0  |  Downloads: 0
Programming Primer Cheat Sheet
Views: 0  |  Downloads: 0
XHTML 1.1 Cheat Sheet
Views: 4  |  Downloads: 2
Geek Speak Cheat Sheet
Views: 7  |  Downloads: 2
Server-side scripting
Views: 19  |  Downloads: 2
Peter Cruickshank - Cheat Sheet
Views: 13  |  Downloads: 0
premium docs
Other docs by armani11
adopt230
Views: 109  |  Downloads: 0
Rejection Letter to Applicant
Views: 622  |  Downloads: 3
r491
Views: 318  |  Downloads: 3
DEMAND FOR PAYMENT
Views: 392  |  Downloads: 11
Receipt For Services in Exchange For_Stock
Views: 420  |  Downloads: 9
BILL OF SALE
Views: 245  |  Downloads: 3
Cover Letterof Copyright Office
Views: 133  |  Downloads: 0