Capt. Horatio T.P. Webb
ASP and PHP
DISC 4372 Transaction Processing II
Parks -- Spring 2009
Version 1 -- Last Updated 2:00 PM 3/1/2009
Function
ASP Syntax (filename.asp)
PHP Syntax (filename.php

Execution

versus

HTLM
pass-thru

<HTML>
<BODY>
Any HTML may be passed outside
the script execution like here.
<%
execution of vbscript code
starts here
...
ends here
%>
any more HTML here
</BODY>
</HTML>
<HTML>
<BODY>
Any HTML may be passed outside
the script execution like here.
<?php
execution of php code
starts here
...
ends here
?>
any more HTML here
</BODY>
</HTML>
Variables typeless (no declaration reqd.)
begin with any [A-Z],[a-z]
contain [A-Z],[a-z],[0-9],_
e.g., some_val7
typeless (no declaration reqd.)
begin with $
contain [A-Z],[a-z],[0-9],_
e.g., $some_val7
Assignment
e.g., some_val7 = 21
e.g., some_val7 = "a string value"
(same as vbscript)
e.g., $some_val7 = 21;
e.g., $some_val7 = "a string value";
(same as javascript)
Strings:
Concatenation
String Length
Locate a string
Extract a string
Replace bytes
uppercase
lower case
 
fred="String one" + "String two"
fred_length = len(fred)
loc_first_x = Instr(1,"abcdexfgh","x")
middle3 = mid("1234567",3,3)
fix_google = replace("gxxgle","x","o",2)
fred = ucase("usa")
alan = lcase("TURING")
 
$fred="String one" . "String two";
$fred_length = strlen($fred);
$loc_first_x = strpos("abcdexfgh","x");
$middle3 = substr("1234567",2,3);
$fix_google = str_replace("gxxgle","x","o",2);
Sfred = strtoupper("usa");
$alan = strtolower("TURING");
Mathematicssame as vbscriptsame as javascript
IF statementssame as vbscriptsame as javascript
LOOPSsame as vbscriptsame as javascript
Form or QueryString Data
Received from the Client
on the client form method=GET:

Request.QueryString("name in the HTML object tag")

or Request.QueryString (index)

where index is an integer that identifies the number of the QueryString name-value pair (begins at 1)

on the client form method=POST:

Request.Form("name in the HTML object tag")

or Request.Form (index)

where index is an integer that identifies the number of the Form name-value pair (begins at 1)

on the client form method=GET:

$_GET["name in the HTML object tag"]

on the client form method=POST:

$_POST["name in the HTML object tag"]

$_REQUEST["name in the HTML object tag"]

retreives value from either GET or POST

Create an ODBC

Connection

or

Recordset

Set cn = Server.CreateObject("ADODB.Connection")
cn.open "dbname","userid","password"
or
Set rs = Server.CreateObject("ADODB.Recordset")
someSQL_string="SELECT ..."
rs.open someSQL_string,"DSN=dbname;UID=userid;PWD=password"
$cn = odbc_connect('dbname','userid','password');
 
or

$someSQL_string="SELECT ...";
$rs = odbc_exec($cn,$someSQL_string);
Recordset close
Connection close
rs.close
cn.close
set rs=nothing
set cn=nothing
odbc_close($conn);
Recordset
Rollout
set rs=Server.CreateObject("ADODB.Recordset")
someSQL="SELECT..."
rs.open someSQL,"DSN=...;UID=...;PWD=..."
while NOT rs.eof
  output values are:
    rs("name of column")
  rs.moveNext
wend
rs.close
set rs=nothing
$conn=odbc_connect('...','...','...');
if (!$conn) exit("Error" . $conn);
$someSQL="SELECT...";
$rs=odbc_exec($conn,$sql);
if (!$rs)exit("rs Error in SQL");
while (odbc_fetch_row($rs))
{
  output values are:
    odbc_result($rs,"name of column");
}
odbc_close($conn);
Simple glmaster
table rollout

NO error handing
is provided

execute this

execute this

Transaction
Conrol
connection_object.BeginTrans
.
.
.
connection_object.CommitTrans

or

connection_object.RollbackTrans

odbc_autocommit(connection_object,false);
.
.
.
odbc_commit(connection_object);

or

odbc_rollback(connection_object);

Execute a
non-query SQL
i.e.,
INSERT
or
UPDATE
or
DELETE
conn_object.execute SQL_string, variable

e.g.,

sql_str="UPDATE glmaster SET balance=0.0 WHERE "
sql_str=sql_str+"major=1000 AND minor=1000 AND sub1=0 AND sub2=0"
cn.execute sql_str,numa
response.write "Number of records affected="+cstr(numa)

e.g.,

The int variable (e.g., numa) returns the number of records affected by the SQL statement

$result_variable=odbc_exec(conn_object,SQL_string);
$variable=odbc_num_rows($result_variable);

e.g.,

$sql_str="UPDATE glmaster SET balance=0.0 WHERE ";
$sql_str=$sql_str+"major=1000 AND minor=1000 AND sub1=0 AND sub2=0";
$res=odbc_exec($cn,$sql);
$numa=odbc_num_rows($res);
echo "numa=".$numa;

The variable (e.g., numa) returns the number of records affected by the SQL statement

CREATE
or
DROP
same as INSERT, etc. above

but returns a -1

same as INSERT, etc. above

but returns a -1