My experience with CGI on windows Apache and MySQL

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

My experience with CGI on windows Apache and MySQL

Post by bangkok » Sun Jan 24, 2010 9:51 pm

I just spent a couple of hours to figure out some stuff about RunRev, CGI and database access.

I'll try to share.

1
I installed :
http://www.uniformserver.com
This package (no need for any installation, just click and run)... allows Windows users to set up an Apache server, along with MySQL and PhP server... Amazing. It's even too easy. :D
Anyway.

2
Then, a quick read of the great CGI tutorial made by Hyperactive Software on :
http://www.hyperactivesw.com/cgitutorial/intro.html

3
-I put the file C:\Program Files\Revolution Enterprise\3.5.0-gm-2\Runtime\Windows\x86-32\standalone
inside the directory : C:\MYSERVER\UniServer\home
Changed the name to "revolution"

-I put the files C:\Program Files\Revolution Enterprise\3.5.0-gm-2\Runtime\Windows\x86-32\Externals\revdb.dll
and C:\Program Files\Revolution Enterprise\3.5.0-gm-2\Runtime\Windows\x86-32\Externals\Database Drivers\dbmysql.dll
(This is the database library and the MySQL driver)
both in C:\MYSERVER\UniServer\home

4
In C:\MYSERVER\UniServer\cgi-bin
I put a "database.cgi" file. I used the method described here by Björnke von Gierke : http://forums.runrev.com/phpBB2/viewtop ... ilit=mysql

Here is the content of file :

Code: Select all

#!C:/MYSERVER/UniServer/home/revolution -ui     -- it won't work without an absolute path

on startup
  set the externals of the templateStack to "C:/MYSERVER/UniServer/home/revdb.dll"
  create stack "externals"
  start using stack "externals"
  revSetDatabaseDriverPath "C:/MYSERVER/UniServer/home"

   put revOpenDatabase("MySQL","127.0.0.1","XXX","XXX","XXX") into dbIDM
   put "SELECT preference where pserie like 'XXXX%'" into dbSQL
   put revDataFromQuery(,,dbIDM,dbSQL) into theData
   put "Content-Type: text/plain" & cr & cr
   put theData

  -- As we have created a stack we need either quit or delete
  -- stack at the end.
  delete stack "externals"
end startup
Et voila !
http://localhost/cgi-bin/database.cgi

It's working fine. Data are displayed.

I love RunRev. :D

Now, I've got no idea if this solution is workable. I mean : creating a stack, then deleting it for each query... Memory issues ?

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: My experience with CGI on windows Apache and MySQL

Post by BvG » Mon Jan 25, 2010 3:20 pm

The engine is approximately 2.3 mb big, the mysql dll is ca 0.5 MB big, and the db external is another 200 kb or so. That's about 3 mb all together.

A stack without gui, on the other hand, is less then 100 kb (i'd guess).

Now you tell me, do you need to worry about that?

Additionally, there is currently no other way then to create a fake stack in memory to load externals, and it's thus the only officially suggested way to use a db.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Redlance305
Posts: 30
Joined: Sun Feb 28, 2010 9:52 pm
Contact:

Re: My experience with CGI on windows Apache and MySQL

Post by Redlance305 » Tue Apr 13, 2010 6:03 pm

Anyone have the sets for setting up CGI database (file names, locations, code) for the Mac?

Been working on this a few days, just found out I need 'drivers'.. DUH, makes sense, no documentation on the matter! <sigh>

As I've said since I started using RunRev, good documentation and examples are needed! Otherwise a wonderful language!

~David

RRobert
Posts: 151
Joined: Sat Feb 28, 2009 8:20 pm

Re: My experience with CGI on windows Apache and MySQL

Post by RRobert » Tue Apr 13, 2010 7:47 pm

Darwin 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386

Revolution 3.5.0-gm-2

$ ls
db.cgi
dbmysql.bundle
revdb.bundle
revolution <- Standalone.app/Contents/MacOS/Standalone

$ cat .htaccess
Options +ExecCGI
AddHandler cgi-script cgi

$ cat db.cgi

Code: Select all

#!revolution -ui

on startup
	
wait 10 milliseconds
send "quit" to me in 5 seconds
	
put "/Users/revolution/Desktop/html/revdb.bundle" into tExternals 
set the externals of the templateStack to tExternals
create stack "externals"
start using stack "externals"

revSetDatabaseDriverPath "/Users/revolution/Desktop/html/"

put "Content-Type: text/html; charset=utf-8" & cr & crlf 
put "Hello World :)" & crlf
		
get revOpenDatabase("mysql", "127.0.0.1", "test", "root", "root")
put it

revCloseDatabase it
put it

quit
end startup
PS: I use the MAMP package.

Edit: If you like to use the shell function dont forget to set "set the shellcommand to "/bin/sh"".

Robert

Post Reply