This is pretty out of date. But in 2000 - this is how I learned PHP.
Here is the original: http://stuff.harperreed.org/misc/Incoming/asptophptojsp.txt
It might be worth it to update, and add python and ruby examples as well. Make it useful for generations to come ;)
ASP :
<% ..... %>
PHP :
<? ..... ?>
JSP :
<%@ page language="java" %> <% ..... %>
ASP :
<% Response.Redirect(url) %>
PHP :
<?
echo("<META http-equiv='refresh' content='0;url=$PHP_SELF?table=$table'>");
exit;
?>
Or Using com function
<? Redirect($url) ?>
JSP :
<jsp:forward page="<%=url%>" />
ASP :
<!--#include file="include/include_com.asp"-->
PHP :
<? include ("./config/base_var.php") ?>
JSP :
<%@ include file="include/include_com.jsp" %>
ASP :
NONE
PHP :
<? echo("$PHP_SELF") ?>
JSP :
NONE
ASP :
user_id = Request("user_id")
PHP :
direct using $user_id
JSP :
String user_id = request.getParameter("user_id");
ASP :
Session("user_id") = user_id
PHP :
No Session. Instead using cookie.
JSP :
HttpSession session = request.getSession(ture);
String str = (String)session.getValue(session.getId());
if (str == null)
{
str = "Session Value";
session.putValue(session.getId(), str);
}
ASP :
If Request.Cookies("login") = "" Then
Response.Cookies("login")=login_id
Response.Cookies("login").Expires=Date+120
End If
PHP :
(Inform: You set the cookie in the first line of your page.)
(Inform: You set the cookie with different name.)
setcookie("user_id","$user_id","now()+3600","/");
setcookie("user_id","$user_id","time()+0","/"); //Release Cookie
JSP :
Cookie[] cookies = request.getCookies();
for (int i=0; i < cookies.length; i++)
{
if (cookies[i].getName() == "login")
{
if (cookie[i].getValue() == null)
{
Cookie loginCookie = new Cookie("login", user_id);
loginCookie.setDomain(url);
loginCookie.setPath("/");
response.addCookie(loginCookie);
}
}
}
ASP :
Sub DB_Connection(conn)
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionTimeout = 60
conn.CommandTimeout = 60
conn.Open "jinybbs", "jinybbs", "" '** ConnectionString, UserID, Password
End Sub
PHP :
function DB_Connection()
{
$conn = mysql_connect("localhost","jinybbs","")
or die("Error: Can't connect to the DB Server");
mysql_select_db("jinybbs", $conn);
return $conn;
}
JSP :
import java.sql.*;
Connection DB_Connection() throws ClassNotFoundException, SQLException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:jinybbs","jinybbs","");
return conn;
}
ASP :
Sub SelectADMIN_Owner(conn, table_owner,is_admin, rs)
sqlstr = " SELECT * FROM ADMIN "
If table_owner <> "*" Then
sqlstr = sqlstr + " WHERE table_owner = '"+table_owner+"' "
End If
If is_admin = "Y" Then
sqlstr = sqlstr + " AND is_admin = 'Y' "
End If
sqlstr = sqlstr + " ORDER BY table_id "
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.CursorType = 3
rs.Open sqlstr, conn
End Sub
PHP :
function SelectADMIN_Owner($conn, $table_owner,$is_admin)
{
$sqlstr = " SELECT * FROM admin " ;
if ($table_owner != "*")
$sqlstr = $sqlstr." WHERE table_owner = '$table_owner' ";
if ($is_admin == "Y")
$sqlstr = $sqlstr." AND is_admin = 'Y' ";
$sqlstr = $sqlstr." ORDER BY table_id ";
$result = mysql_query($sqlstr)
or die("Error: Not Good Query Statement: ".mysql_error());
return $result;
}
JSP :
ResultSet SelectADMIN_Owner(Connection conn, String table_owner) throws SQLException
{
Statement stmt = conn.createStatement();
String sqlstr = " SELECT * FROM admin " ;
ResultSet rs = stmt.executeQuery(sqlstr,TYPEFORWARD_ONLY); (or TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE)
return (rs==null)?null:rs;
}
ASP :
<% Do While Not rs.EOF %>
<% If rs("is_admin") = "N" Then %>
<OPTION value="<%=rs("table_name")%>"><%=rs("table_alias")%>
<% End If %>
<% rs.MoveNext
Loop %>
PHP :
<?
while($row = mysql_fetch_array($result))
{
if ($row[is_admin] == "N")
echo("<OPTION value='$row[table_name]'>$row[table_alias]");
}
?>
JSP :
<%
while(rs.next())
{
String is_admin = new String(rs.getString("is_admin").getBytes("KSC5601"),"8859_1");
if (is_admin == "N")
{
out.println("<OPTION value='"+rs.getString("table_name")+"'>"+rs.getString("table_alias).getBytes("KSC5601"),"8859_1"));
}
}
%>
(asp_tags = Off ; allow ASP-style <% %> tags at php3.ini) ASP :
<%=user_id%>
PHP :
<? echo($user_id) ?>
JSP :
<%=user_id%>
ASP :
<% Call CopyRightLogo %>
PHP :
<? CopyRightLogo() ?>
JSP :
<% CopyRightLogo() %>
ASP :
If Not rs.EOF Then ... ' Exist Record Set Else url = "../db_fail.asp" ' No Record End If
PHP :
if($row = mysql_fetch_array($result)) ....; // Exist else ....; // No RecordSet or if($result) ...
JSP :
if(rs.next())
{
}
else
{
}
ASP :
Call DB_Connection(jinybbs_db) Call SelectADMIN_Owner(jinybbs_db, "*", "", rs)
PHP :
$connect = DB_Connection(); $result = SelectADMIN_Owner($connect, "*", "");
JSP :
Connection jinybbs_db = DB_Connection(); ResultSet rs = SelectADMIN_Owner(jinybbs_db,"*","");
ASP :
rs.MoveLast postcount = rs.RecordCount
PHP :
$postcount = mysql_affected_rows();
JSP :
rs.Last(); int postcount = rs.getRow();
ASP :
\ (Integer Division) Mod (Modulus) <> (Not Equal)
PHP :
floor(a/b) (Integer Division) % (Modulus) != (Not Equal)
ASP :
For i=1 To ipp ... Next
PHP :
for($i=1;$i<=$ipp;$i++)
{
...
}
JSP :
for (int i=1; i <=ipp; i++)
{
...
}
(SQL*Server is good for Transaction, but MySQL don't work Transaction) ASP :
On Error Resume Next jinybbs_db.BeginTrans Call InsertADMIN(jinybbs_db, table_name, table_alias, table_desc, table_owner, table_passwd,"N") If jinybbs_db.Errors.Count = 0 Then jinybbs_db.CommitTrans ' Successful Commit ... Else jinybbs_db.RollbackTrans ' Fail Rollback End If
PHP :
$result = InsertADMIN($connect, $table_name, $table_alias, $table_desc, $table_owner, $table_passwd,"N")
if($result)
{ //Successful
}
else
{ //fail
}
JSP :
for update, insert, delete transaction(using executeUpdate)
jinybbs_db.setAutoCommit(false);
int trans1 = InsertADMIN(jinybbs_db, table_name, table_alias...);
int trans2 = InsertADMIN2(jinybbs_db, table_name, table_alias...);
if ((trans1 >0) && (trans2 > 0)
{
jinybbs_db.commit();
}
else
{
jinybbs_db.rollback();
}
* For InsertADMIN
int InsertADMIN(Connection conn, ...)
{
Statement stmt = conn.createStatement();
String sqlstr = "INSERT INTO ADMIN ...";
stmt.executeUpdate(sqlstr);
int trans = stmt.getUpdateCount();
return trans;
}
ASP :
If DateDiff("d",rs("create_date"),now)<1 Then
... ' Today
End If
PHP :
$today = date("Y.m.d",time());
$compday = date("Y.m.d",$row[create_date);
If ($today == $compday)
... //Today
End If
Or using Function
if (DateDiff($row[create_date])
... //Today
JSP :
ASP :
Len() Left, Right
PHP :
strlen() substr($string,0,17)
JSP :
ASP :
<%=Formatdatetime(rs("create_date"),2) %>
PHP :
<? echo(date("Y.m.d",$row[create_date]) ?>
ASP :
subject = CheckQuoteMark(Request("subject")) (util_com.asp)
PHP :
$subject = addslashes($subject);
ASP :
subject = CheckQuoteMarkUpWithCR(rs("subject")) (util_com.asp)
PHP :
$subject = stripslashes($row[subject]);