Forum Moderators: phranque

Message Too Old, No Replies

Porting .ASP from Windows IIS to Linux ChilliSoft ASP

What are the conversion issues?

         

sun818

9:39 pm on Oct 9, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



We have a site hosted on a Windows web server with an Access DB. What kind of migration issues will we face when we move to ChilliSoft ASP on a Linux box? My initial concerns are:

1. getting AccessDB to mySQL
2. ADO/ODBC driver availability?
3. Coding ActiveX DLLs not on Linux?

Anything else?

txbakers

10:06 pm on Oct 9, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Access DB to mySQL is very easy. download to text files from Access, import into mySQL.

There is a myODBC driver available for mySQL from their website.

Can't help with the third one.

PLEASE - post your progress with this as I might want to do the same thing in a few months.

markseeker

3:47 pm on Oct 16, 2002 (gmt 0)

10+ Year Member


This document describe the transition I have experienced in the transition from Microsoft ASP and Access to using Chillisoft ASP and MySQL on a Linux server.

The main difference in the actual coding are related to the SQL statements and some of the more specific coding like that for the uploading of images. Id look closely to the documents from the chillisoft web site as this is where I got all my information.

The system I've have being using is a Linux system using the latest chillisoft.

Basic knowledge from Microsoft's ASP script is needed to read further, or people starting out using chillisoft.

-----------------------------ALL BELOW CODE SHOULD WORK WITH LITTLE CHANGE.
<HTML>
<BODY>
-----FIRST TO INSERT NEW DATA INTO MEMBERS TABLE---
<br>
<%
'---set up vars (normally you would get these from a form etc.)
varname="Mark" '--just my name in text
vardate=Date '--this should ge to days date
varsessionid=Session.SessionID '--this will get the session number for the user

'---------set dims--
Dim oConn 'connection object
Dim oRS 'rescordset object
'--make conection to mysql database
set oConn = Server.CreateObject("ADODB.Connection"[smilestopper])
set oRS = Server.CreateObject("ADODB.Recordset"[smilestopper])
oConn.Open "Driver={mySQL}; Server=localhost; Port=3306; Option=0; Socket=; Stmt=; Database=yourdatabase; Uid=userid; Pwd=password;"
oRS.ActiveConnection = oConn

if oConn.errors.count = 0 then
'--now make sql statement
sqltext = "INSERT INTO `members` SET"&_
" `name` = '" & varname & "',"&_
" `date` = '" & vardateit & "',"&_
" `sessionid` = '" & varsessionid & "';"

'--now run sql statement
oRS.Open sqltext,oConn
end if

'--now close connection
oConn.Close
Set oConn = Nothing
Set oRS = Nothing
%>
<br>
---NOW GET INFORMATION OUT OF TABLE--
<br>
<%
'---------set dims--
Dim oConn 'connection object
Dim oRS 'rescordset object
'--make conection to mysql database
set oConn = Server.CreateObject("ADODB.Connection"[smilestopper])
set oRS = Server.CreateObject("ADODB.Recordset"[smilestopper])
oConn.Open "Driver={mySQL}; Server=localhost; Port=3306; Option=0; Socket=; Stmt=; Database=yourdatabase; Uid=userid; Pwd=password;"
oRS.ActiveConnection = oConn

if oConn.errors.count = 0 then
sqltext = "SELECT * FROM `members` WHERE `name`='" & varname & "';"
oRS.Open sqltext,oConn
If oRS.RecordCount > 0 Then
vardate=oRS("date"[smilestopper])
varsessionid=oRS("sessionid"[smilestopper])
response.write "Date: " & vardate & " ¦ Session id: " & varsessionid
end if
oRS.Close
end if

'--now close connection
oConn.Close
Set oConn = Nothing
Set oRS = Nothing
%>
<br>
-------NOW LETS UPDATE THIS INFORMATION---
<br>
<%
'---set up vars (normially you would get these from a form etc.)
vardate=Date '--this should be to days date
varsessionid=Session.SessionID '--this will get the session number for the user

'---------set dims--
Dim oConn 'connection object
Dim oRS 'rescordset object
'--make conection to mysql database
set oConn = Server.CreateObject("ADODB.Connection"[smilestopper])
set oRS = Server.CreateObject("ADODB.Recordset"[smilestopper])
oConn.Open "Driver={mySQL}; Server=localhost; Port=3306; Option=0; Socket=; Stmt=; Database=yourdatabase; Uid=userid; Pwd=password;"
oRS.ActiveConnection = oConn
if oConn.errors.count = 0 then
'-----------------SQL TEXT---->
sqltext1 = "UPDATE `members` SET"&_
" `date` = '" & vardate & "',"&_
" `sessionid` = '" & varsessionid & "' WHERE `name` = '" & varmemnamec & "' AND `pass` = '" & varmempassc & "' LIMIT 1;"
'-------------------------->
oRS.Open sqltext1,oConn
'--note here that their is no (oRS.Close) command. I've tried entering this and always come up with an error. so for now I've found it works fine with out it.
'--now close connection
oConn.Close
Set oConn = Nothing
Set oRS = Nothing
%>
<br>
--UPDATE FINISHED--
</BODY>
<HTML>

----------------END OF COPING CODE ---------------

OK now for a few other tricks that need to be addressed.
As the code changes so do those little problems we always have to find a way around. The first one I hit was this one.
As you notice in the above code the symbol (`) is an important one, an if repeated in the sql statement will brake the sql statement and course an error.
to get around this problem, when ever accepting data from a form I have chosen to use the replace method.
like so:

<%
varid = replace(Request.form("id"[smilestopper]),"'","`"[smilestopper])
%>

(varid) is the new variable I will later put in my sql statement.
so then it looks like this:

<%
varid = replace(Request.form("id"[smilestopper]),"'","`"[smilestopper])
sqltext = "SELECT `name` FROM `members` WHERE `session`='" & varid & "';"
'--open oRS connection here.
%>

OR you can also chose to do this:

<%
varid = replace(Request.form("id"[smilestopper]),"'","`"[smilestopper])
sqltext = "SELECT `name` FROM `members` WHERE `session`='" & varid & "';"
'--open oRS connection here.
%>

Some other handy code I almost always use for testing is this :

<%
DIM formElement
FOR EACH formElement IN Request.Form
Response.write formElement & " = " & Server.HTMLEncode(Request.form( formElement )) & "<br>"
NEXT
%>

This code will show the name and values of every field in the form that opened the page running this code.
(if that makes sense)
This code can also be made to get out form information from the (GET) method
so make (Request.form) into (Request.querystring)

Another one is to check for real emails:

<%
if (instr(varmememail,"@"[smilestopper])>0 and instr(varmememail,"."[smilestopper])>0 and len(varmememail)>5) then
Response.write "real email"
else
Response.write "not real email"
end if
%>

This is not fool proof by any means but does the job.

Another thing is uploading images.
First thing the permissions have to be set to read and write on the correct folder to upload the images with no errors occurring.

On the fist page should be the following:

<html>
<body>
<form name="form2" method="post" action="uploadpicture-file.aspuploadpicture-file.asp?membername=<%=varname%>" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="FILE">
<INPUT TYPE="submit" VALUE="Send" name="Submit">
</form>
</body>
</html>

Now you need the uploadpicture-file.asp file set up:

<html>
<body>
<%
'--------------------------------------------------------------
Response.Expires = 0
Set fbase = Server.CreateObject("Chili.Upload.1"[smilestopper])
'-- for file less than 30k big, and must be a jpg file
if fbase.FileSize <= 30000 then
filename = Mid(fbase.SourceFileName, InstrRev(fbase.SourceFileName, "\"[smilestopper]) + 1)
if (fbase.SourceFileExtension = ".jpg"[smilestopper]) then
'=============================================================

'---------set dims--
Dim oConn 'connection object
Dim oRS 'rescordset object
'--make conection to mysql database
set oConn = Server.CreateObject("ADODB.Connection"[smilestopper])
set oRS = Server.CreateObject("ADODB.Recordset"[smilestopper])
oConn.Open "Driver={mySQL}; Server=localhost; Port=3306; Option=0; Socket=; Stmt=; Database=yourdatabase; Uid=userid; Pwd=password;"
oRS.ActiveConnection = oConn
if oConn.errors.count = 0 then
'--files will be uploaded to the (memimage) folder
varname = Request.querystring("membername"[smilestopper])
filename = "memimage\" & varname & ".jpg"

Response.write "<br> this should look something like (memimage\Mark.jpg) :" & filename & "<br>"
'--now set up SQL statement
sqltextimg = "UPDATE `member` SET `image`='" & varname & ".jpg" & "' WHERE `name` ='" & varname & "' LIMIT 1;"
oRS.Open sqltextimg,oConn
end if
'--now close connection
oConn.Close
Set oConn = Nothing
Set oRS = Nothing

'===========================================================
fbase.SaveToFile(Server.mapPath(filename))
end if
%>
<p>Done writing <%=fbase.FileSize%> bytes from user file <%=fbase.SourceFileName%>
(of type <%=fbase.SourceFileExtension%>[smilestopper]) </p>
<hr>
</body>
</html>

Are you and assie like me and want to display the date around the way that really should be standard:
etc: 20/11/2000

<%
'---lets say the server chooses 11/26/2001 as to days date.
vardate = Date
'---now it is split at each ( / ) mark.
datespldate=split(vardate,"/"[smilestopper])
'--now lets rearrange the order.
vardate=(datespldate(2) & "/" & datespldate(0) & "/" & datespldate(1))
%>

So now vardate is (26/11/2001). I've used this one a lot.

If your using Cookies, they are coded the same way as Microsoft will teach its ASP code.
Set up varmemname and password from mform ect.
then use the following:
<%
'-----------SIGN IN MEMBER NOW USING COOKIE FOR THIS SESSION ONLY-----
Response.Cookies("myurl.com-auto"[smilestopper])("varmemname"[smilestopper])= varmemname
Response.Cookies("myurl.com-auto"[smilestopper])("varmempass"[smilestopper])= varmempass
'----------SIGN IN MEMBER ALWAYS---------
if (varmemautosign = "1"[smilestopper]) then
Response.Cookies("myurl.com-auto"[smilestopper]).Expires= "12/12/2030"
end if
'----Get Cookie info ------------------------------------------
varmemnamec = Request.Cookies("myurl.com-auto"[smilestopper])("varmemname"[smilestopper])
varmempassc = Request.Cookies("myurlcom-auto"[smilestopper])("varmempass"[smilestopper])
'--now use as you wish.

%>

That covers the code I really found useful the last few months I've being making the transition.

I run my own business at www.spiderweboptions.com.au
I hope this was of help, i dont usually spend 2hrs replying to these forums but i found getting the stuff hard work and I hope its of use to you.

[1][[b]edited by[/b]: markseeker at 3:53 pm (utc) on Oct. 16, 2002][/1]

markseeker

3:51 pm on Oct 16, 2002 (gmt 0)

10+ Year Member


PS
The font on this page seems to stuff up some of the script. *Note that you should copy all of my first post and put it into anther font to see all the (`) marks easily.