LC Server database connection

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

LC Server database connection

Post by AxWald » Thu May 27, 2021 12:11 pm

Hi,
there's something I'm doing wrong. What is it?

Code: Select all

<?lc
put revdb_connect("mysql", "localhost", "DBName", "DBUser", "DBPassword")
?>
This should return a connectionID, right? Not:

Code: Select all

Function: error in function handler (revdb_connect)
If I do a "try" I get ErrNums 219 and 223 (Error in expression/ function handler).
I don't get any return values from the function, and "the result" is empty.

I have the correct values in place - in fact, values that work flawlessly when called on desktop.
I have tried both "localhost" and "myDomain.com".
I have tried w/o the spaces after the commata. And anything else that came to mind.
The DB allows to connect to from everywhere.
And the CGI does work with all kind of other requests.

Any ideas? Thx & have fun!

Edit & PS: I'm using LC Server 8.1/ 8.2dp2 64bit, as CGI, on Ubuntu Server 20.04
Last edited by AxWald on Thu May 27, 2021 4:13 pm, edited 1 time in total.
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: LC Server database connection

Post by Klaus » Thu May 27, 2021 12:46 pm

Hi AxWald,

doesn't it have to read:

Code: Select all

...
put revopendatabase("mysql", "localhost", "DBName", "DBUser", "DBPassword")
...
Best

Klaus

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: LC Server database connection

Post by AxWald » Thu May 27, 2021 4:05 pm

Hi,

"revdb_connect" and "revOpenDatabase" are equivalent.
I prefer the "revdb_*" versions because they're all functions, and because they all share a significant beginning.

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: LC Server database connection

Post by Klaus » Thu May 27, 2021 4:18 pm

Ah, sorry, didn't know that.

However after looking at the Dictionary, revOpenDataBase/revdb_conncet is only available on:
-> mac, windows, linux, ios, android

No mention of HTML5. :(

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: LC Server database connection

Post by AxWald » Sun May 30, 2021 11:30 am

Hi,

just to clarify:
I want a LC Server, running on a Linux server as CGI processor, to connect to a mySQL on this same Linux server.
The mySQL works fine, I can easily connect to it via PHP.
The LC server works fine, I can throw all kinds of scripts at it & it replies faithfully.
My connection string works flawlessly when fired from a desktop/ mobile LC program.
(And I'm no db noob, I work with dbs daily since years, just only on desktop & mobile ...)

But:
When using "revdb_connect" or "revOpenDatabase", with whatever combination of arguments, I get "Expression error" from the LC server. Not a ("revdberr") database error!

Anybody can tell me at least if LC Server (v8*, 64bit, Linux) can connect to DBs at all? I'm quite stunned here, to be honest.

Thx & have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: LC Server database connection

Post by SparkOut » Sun May 30, 2021 4:01 pm

Instead of localhost, try 127.0.0.1

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: LC Server database connection

Post by AxWald » Sun May 30, 2021 5:27 pm

Hi,

doesn't change anything. I've tried all sorts of parameter combinations - but all I get is a "expression error". As if the server wouldn't have its "revdb.so" & so would not recognize the db functions.

But they're in the appropriate directories, and I even tried to chmod 755 them. Is there a way to test if the database libraries are loaded?

Code: Select all

   get revDB_disconnect(1)
returns the same "expression error" - looks like the database lib isn't recognized. :/

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: LC Server database connection

Post by Klaus » Sun May 30, 2021 5:50 pm

Klaus wrote:
Thu May 27, 2021 4:18 pm
...
However after looking at the Dictionary, revOpenDataBase/revdb_conncet is only available on:
-> mac, windows, linux, ios, android
No mention of HTML5. :(
Sorry, this is of course a LC SERVER question and not about HTML5. :oops:

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: LC Server database connection

Post by AxWald » Mon May 31, 2021 2:41 pm

Hi,

filed this as a bug.

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: LC Server database connection

Post by AxWald » Sat Jul 24, 2021 7:57 pm

Hi,

roaring silence here, and @ quality control :/

Should anybody actually use a LC server (64bit Linux) to connect to any databases, I'd be more than happy to read a quick line from you, even if it's just something like "Tried 8.? on debian & it worked"!

From current knowledge, it could well be that LC server is used only rarely, and that the db functionality is broken since ages, undetected. It looks like the *.so externals don't get loaded for some strange reason:
"put (there is a stack "revdatabaselibrary")" => "false"

I'd try to load them explicitly in the hope to get a helpful error message at least, but found no hint how to do this. A similar question in another context ("how to provide revdb.dll to an already running StandAlone?") didn't provide any answers, too. Any ideas, anybody?

Thx for any answers, have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: LC Server database connection

Post by SparkOut » Sat Jul 24, 2021 9:07 pm

I have multiple instances of LiveCode server (version 9.*) working to interact with databases on Linux x64 servers.
I can't remember whether I ever had v 8.* on but they have been running for years in .htaccess mode since at least v 7.* and updated periodically so I dare say I could have jumped straight from 7 to 9 but I have not had any such errors in any version.
The revdb.so file has 0755 permissions and is located in the "externals" folder in the cgi-bin folder alongside the LiveCode Server engine file. The externals folder also has 0755 permissions FWIW.
So yes, it LC server definitely works with mySQL databases.
The database is always on the same host as LC server and the connection string always uses 127.0.0.1 rather than localhost.
When I can use my computer rather than phone I will try and show sample code I use to create the connection, and see of you can spot what is different for you that might cause your problems. But as you mention, it seems like the library itself isn't being loaded, so first investigate location and permissions of the revdb.so

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: LC Server database connection

Post by AxWald » Mon Jul 26, 2021 4:43 pm

Hi,

the LC server configuration is 100% correct (with ./externals/revdb.so & ./drivers/dbmysql.so), as in the zip. All files & folders are 755.

The whole thing runs completely fine as CGI - it just doesn't load its externals :/ Not in any LC 8/64 server version that I tried. Why it is this way - no idea.

I cannot try the 9.* versions because they require a whole bunch of font dependencies that isn't available on real Linux production servers. A Ubuntu "server edition", for instance, doesn't contain them, to start with. (The 8.* series is less demanding)

Guess I'll better scrap my LC server ideas, and learn a bit more PHP.

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

matthiasr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 190
Joined: Sat Apr 08, 2006 7:55 am
Location: Lübbecke, Germany
Contact:

Re: LC Server database connection

Post by matthiasr » Mon Jul 26, 2021 5:00 pm

Should anybody actually use a LC server (64bit Linux) to connect to any databases,
We are using Livecode Server 9.6.1 Pro here daily to communicate to a MariaDB, but through https:// calls, not directly on the command line?

I just tried to install a version 8 on one of my HostM accounts, but it seems that due to new security restrictions it is not possible anymore to do custom Livecode Server installations. I will try later today to install a version 8 onto my On-Rev account. Will test DB connection then and will let you know.

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: LC Server database connection

Post by AxWald » Mon Jul 26, 2021 9:00 pm

Hi,

Just to clarify again - it's not a problem with a certain database. It's not about wrong paths or permissions (if not all & any documentation is wrong). It's about "revdb.so" that doesn't get loaded, for whatever reason.

To demonstrate it I try to close a non-existent db connection:

Code: Select all

<?lc
put revdb_disconnect(1)
?>
is expected to return (this is what it does on desktop):

Code: Select all

External execution error:
Error description: revdberr,invalid connection id
An error in the external, "1" is indeed an invalid connection id.
But LC server returns:

Code: Select all

file "/www/htdocs/xyz/domain.com/cgi-bin/_test_db.lc"
  row 2, col 5: Function: error in function handler (revdb_disconnect)
  row 2, col 5: put: error in expression
It doesn't recognize the function "revdb_disconnect" :/


So a direct test if the db lib is loaded (desktop would say: true):

Code: Select all

<?lc
try
get (there is a stack "revdatabaselibrary")
catch myErr
end try
put "It:" & it & "<br>" & "Result: " & the result & "<br>" & CR & "Error: " & myErr
?>
returns:

Code: Select all

It:false
Result:
Error:
The db lib is not loaded, and there's no error in the script ("Result" would be a script error, "Error" would be a system error).

This is LC 8/64 Linux server community version as CGI, tried on a real production server running Ubuntu 20.04.

Is it possible that modern servers don't load .so's?

Thx all, and have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

matthiasr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 190
Joined: Sat Apr 08, 2006 7:55 am
Location: Lübbecke, Germany
Contact:

Re: LC Server database connection

Post by matthiasr » Mon Jul 26, 2021 9:21 pm

I've just tested on an On-Rev account with a custom installation of LC sever 8.1.10 commercial.
The os is Linux. The kernel build is 3.10.0-1062.9.1.el7.x86_64. Unfortunately there is no more information about the running Linux version.

The following script is executed and the data from the DB is fetched and displayed in the Browser. There is no error

Code: Select all

put revopendatabase("mysql","localhost",tDB,tUser,tPass) into tDBid
put tDBID &&"<br><br>"
put "select * from lctest" into tSQL
put revdatafromquery(";",CRLF,tDBID,tSQL)
revclosedatabase tDBID
But executing revclosedatabase without any revopendatabase before
e.g.

Code: Select all

put "Livecode Server Version : "& the Version &"<br><br>"
revclosedatabase 33
put the result && it
returns the following error

Code: Select all

file "/home/matthias/public_html/mr2.lc"
  row 5, col 1: External handler: exception (revdberr)
  row 5, col 1: Handler: can't find handler (revclosedatabase)
Maybe the DB external is initialized the first time revopendatabase() is called.

This all does not help you with your problem, but shows at least Livecode Server is 8.1.10 is working with DB as expected.



[Edit]One thing i just noticed

calling just

Code: Select all

put revdb_disconnect(44)
instead of

Code: Select all

revclosedatabase 44
. without any revopendatabase() before

returns exact the same error you are experiencing

row 6, col 5: External handler: exception (revdberr)
row 6, col 5: Function: error in function handler (revdb_disconnect)
row 6, col 5: put: error in expression

Post Reply

Return to “CGIs and the Server”