how to convert asp to php

Posted on 2003-03-31
Medium Priority
Last Modified: 2008-02-01
HI, i have few pages created in asp, and i just found out that my webserver is not supporting asp (post method) they told me to use PHP. but i am still learning and i need to finish by end of this week. below code i need to tranfer in to PHP. can someone help me out please. Thanks.

ASP code

<body bgcolor="#786854"  text="#FFFFB9">

Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adUseClient = 3
Const adCmdText = 1

Dim conn, rs, connString, qString

set conn=Server.CreateObject("ADODB.Connection")
set oRs=Server.CreateObject("ADODB.recordset")


conn.Open connString

Pictures Page
  Dim mypage, numpages, numrecs, pagesize

  mypage = CInt( Request("page") )
  If mypage=0 Then mypage=1

  pagesize = CInt( Request("recs") )
  If pagesize = 0 Then pagesize = 10    ' If we aren't given a value use 10

  Set rs = Server.CreateObject("ADODB.RecordSet")
  rs.PageSize = pagesize
  rs.CacheSize = pagesize
  rs.CursorLocation = adUseClient

  qString = "SELECT * FROM Table1"
  rs.Open qString, conn, adOpenForwardOnly, adLockReadOnly, adCmdText

  numpages = rs.PageCount
  numrecs = rs.RecordCount

  If mypage > numpages Then mypage = numpages
  If mypage < 1 Then mypage = 1

  rs.AbsolutePage = mypage

  Response.Write("<P> <B>" & numrecs & " records found.</B>" )
  Response.Write("<BR> Page " & mypage & " of " & numpages & "</P>")


  Dim i
  For i=1 To pagesize
    If NOT rs.EOF Then
      'Response.Write(rs("Name") & " | " & rs("Data") & " <BR>")
      response.Write "<tr><a href='http://home.1asphost.com/Yash/images/" & rs("Images") & "'> <img src=images/" & rs("Images") & " border=5 celspacing=5 width=175 height=175></a></tr>"

    End If


  Dim x, lb, ub
  For x=1 To numpages
    lb = (x-1) * pagesize + 1
    ub = x * pagesize
    If ub > numrecs Then ub = numrecs
    If x <> mypage Then
      Response.Write("<A HREF=pictures.asp?page=" & x & "&recs=" & pagesize & ">" & lb & "-" & ub & "</A>")
      Response.Write(lb & "-" & ub)
    End If
    If x <> numpages Then Response.Write(" | ")


  Set rs = Nothing
  Set conn = Nothing


Question by:ydeewana
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8249237
you don't really expect *anyone* will convert this code into PHP for "20 points", do you? :-)
ASP and PHP practically have nothing in common, so any 'convertion' of a ASP script will be a complete re-write of that very script -- with a few exceptions like the SELECT statement in the one you posted ;-)

There are some "ASP emulators" for PHP, but according to "them, telling you to use PHP", none is installed on their system.

1.) Your script is using a database, which requires a total different approach *and* a different database engine in a typical LAMP system.
I assume "they" are running a Linux box (the 'L' in LAMP), so may have access to a MySQL (resposible for the 'M') or PostgreSQL database server -- if at all --, and you should check this first.
Both DBs mentioned require different PHP code unless using a generic db-layer, and a proper 'mirror' of the DB tables you currently have in that Access file.
The PHP code to handle the database request also differs from the ADODB*) object model in ASP.
In general you can't simply use an Access MDB file on a linux box and you *should not* use one on a production server either.

2.) Your script appears to be some sort of an "Image/Picture Gallery". Instead of converting this one just go ahead an download one of the billion galleries available for PHP. Some of them require a database, some don't.
Get a simple one to start with, then get familiar with PHP and it's principles of databases connections, and then make "your script" as sophisticated as you want.
Btw: if you're familiar JavaScript you'll find out that PHP has much more in common with JS than VBscript/ASP.

Unfortunately I can't provide you with any link to a certain gallery-script because I always coded them by myself with respect to a site's specific layout etc.

Here are some links you can search for "gallery"
 - http://www.phpfreaks.com/
 - http://php.resourceindex.com/
 - http://www.hotscripts.com/PHP/
 - http://px.sklar.com/search.html

They were all listed at http://www.php.net/links.php

And of course: go and get the PHP manual from http://www.php.net/download-docs.php (available in many languages)
If you are running Windows I recommend the 'CHM/Windows Help' format as it allows a full text search.

Have fun


*) there's an object oriented database abstraction layer for PHP (nice term<g>) called ADODB as well, providing similar functionality as and is AFAIK "inspired" by the "original" ADODB.

Author Comment

ID: 8253408

First of all Thanks for the information. I know that  points are very low for this questions. I did not expect anyone to convert my code from ASP to PHP. There are few reasons i put my code there. one was when i put it, i did not know how that works. Second, when i search online, i found there are few converter which will allow you to convert code from ASP to PHP. Therefore i thought they someone might have done it.

anyway, Thanks again for providing me good information.


Accepted Solution

Scrit earned 80 total points
ID: 8744235
ASP to PHP conversion helper from
did this conversion by one button click:
(You may still need work on database part though...)
Good Luck.

<?php // require("../replacers.inc");

<body bgcolor="#786854"  text="#FFFFB9">
Pictures Page
   if($mypage == 0){$mypage=1;
   if($pagesize == 0){$pagesize=10;// If we aren't given a value use 10
   $qstring="SELECT * FROM Table1";
   if($mypage > $numpages){$mypage=$numpages;
   if($mypage < 1){$mypage=1;
   echo("<P> <B>" . $numrecs . " records found.</B>");
   echo("<BR> Page " . $mypage . " of " . $numpages . "</P>");
   for($i=1; $i<=$pagesize;  $i+=1){
         //Response.Write(rs("Name") & " | " & rs("Data") & " <BR>")
         echo("<tr><a href='http://home.1asphost.com/Yash/images/" . $rs["Images"] . "'> <img src=images/" . $rs["Images"] . " border=5 celspacing=5 width=175 height=175></a></tr>");
   for($x=1; $x<=$numpages;  $x+=1){
      $lb=($x - 1) * $pagesize + 1;
      $ub=$x * $pagesize;
      if($ub > $numrecs){$ub=$numrecs;
      if($x != $mypage){
         echo("<A HREF=pictures.asp?page=" . $x . "&recs=" . $pagesize . ">" . $lb . "-" . $ub . "</A>");
      }else {
         echo($lb . "-" . $ub);
      if($x != $numpages){echo(" | ");

LVL 33

Expert Comment

ID: 11942890
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: Scrit {http:#8744235}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question