luasql.mysql

Hey guys,

i want to connect to my mySQL Webserver and i saw that there are code examples for this but they always need:

require "luasql.mysql";

How do i get this “luasql.mysql” ?

I know that there is this website: http://keplerproject.github.io/luasql/

But i dont know how to make this work for my project and on the website they say you have to “install” the drivers but how can you install an git project? o.O

Hope someone can help me :slight_smile:

You can’t use external libraries with Corona that way.

That is, if the module is not pure-Lua, it won’t work.

Most LuaRocks stuff is compiled into a special build of Lua.

To clarify, you’ve got different versions and builds of Lua:

  • Pure-Lua 5.0, 5.1, 5.2, 5.3 …
  • Lua built into Corona (w/ minor tweaks), currently equal to Lua 5.2 (or is it 5.1?)
  • Lua + Libraries
    • LuaRocks
    • Others

You can pure-Lua modules from anywhere as long as they work with the same version of Lua as Corona has embedded.

Note: You should be checking this out (for SQL lite): 

https://docs.coronalabs.com/daily/api/library/sqlite3/index.html

or find a pure-Lua mySQL module.

Honestly, unless you’re building a desktop app for people who have MySQL installed, you probably will run into security issues before you even try to get to coding. Most sensible ISP’s will hide MySQL access behind the firewall so that only hosts running on their network can access them. I certainly would not want a database of mine accessible directly from the Internet. You can write short PHP or .NET scripts (or whatever server scripting flavor you like) that will take an http/https network.request(), parse the inbound data, sanitize it to remove any SQL injection hacks, and let the script to the actual database work peacefully behind the firewall.

Said script can output JSON and your network.request() can take that string and using our JSON library calls turn it neatly into a Lua table for your app to use.

Rob

o

hi,

I’ve seen several requests for luasql to be added to or as an option in future corona builds and response is to use the raw language build, some other build of lua, or use sqllite. none of those options are viable if you like the corona SDK and apps with data from MySQL or other db sources.

it would be a Great asset to be able to spread the word and get corona SDK in more hands if luasql was incorporated, the alternative is a programming nightmare which I’m sure no one likes.

is there any likelihood of this happening either in the near future or far future? or is it a dead issue??? the answer will depend on my personal use of lua which would be greatly limited… and unfortunate for us who like data in our apps. thanks, daveC

I saw a feature request come through. That’s great because that’s the starting point. 

To help me understand the context, are you looking to build a mobile app or a desktop app?

Is your MySQL server public facing? That is:  can one connect to port 3306 from any computer?

Thanks

Rob

rob, thanks for the reply. primarily mobile apps with remote MySQL database connection via 3306 like port, but I have a proprietary connection scheme for security but that shouldn’t interfere, I do use 3306 for testing though, so something like luasql would be a big help in getting apps to work, then the port would be easy. thanks again.

@davidjcantera, no apps natively connect to MySQL if they do that is a seriously bad implementation of a database layer as a database should always (without exception) reside behind an application layer.  Otherwise people will simply port scan your server and find a MySQL instance responding and they will have a field day!

If your app can natively connect to a MySQL instance then so can anyone else and rest assured there are thousands of idiots that spend their life trying to find insecure instances to take down/corrupt just for kicks.

DBs should be hidden behind firewalls and only accessible by accessing some form of web service with token authentication served via https.

hmmm… I wonder why MySQL wrote this in their docs…  https://dev.mysql.com/doc/refman/5.6/en/using-secure-connections.html

https://dev.mysql.com/doc/refman/5.6/en/secure-connections.html

ok, I see your point, I don’t want the data exposed. I’ll research the alternative you mentioned. thanks, daveC

You can’t use external libraries with Corona that way.

That is, if the module is not pure-Lua, it won’t work.

Most LuaRocks stuff is compiled into a special build of Lua.

To clarify, you’ve got different versions and builds of Lua:

  • Pure-Lua 5.0, 5.1, 5.2, 5.3 …
  • Lua built into Corona (w/ minor tweaks), currently equal to Lua 5.2 (or is it 5.1?)
  • Lua + Libraries
    • LuaRocks
    • Others

You can pure-Lua modules from anywhere as long as they work with the same version of Lua as Corona has embedded.

Note: You should be checking this out (for SQL lite): 

https://docs.coronalabs.com/daily/api/library/sqlite3/index.html

or find a pure-Lua mySQL module.

Honestly, unless you’re building a desktop app for people who have MySQL installed, you probably will run into security issues before you even try to get to coding. Most sensible ISP’s will hide MySQL access behind the firewall so that only hosts running on their network can access them. I certainly would not want a database of mine accessible directly from the Internet. You can write short PHP or .NET scripts (or whatever server scripting flavor you like) that will take an http/https network.request(), parse the inbound data, sanitize it to remove any SQL injection hacks, and let the script to the actual database work peacefully behind the firewall.

Said script can output JSON and your network.request() can take that string and using our JSON library calls turn it neatly into a Lua table for your app to use.

Rob

o

hi,

I’ve seen several requests for luasql to be added to or as an option in future corona builds and response is to use the raw language build, some other build of lua, or use sqllite. none of those options are viable if you like the corona SDK and apps with data from MySQL or other db sources.

it would be a Great asset to be able to spread the word and get corona SDK in more hands if luasql was incorporated, the alternative is a programming nightmare which I’m sure no one likes.

is there any likelihood of this happening either in the near future or far future? or is it a dead issue??? the answer will depend on my personal use of lua which would be greatly limited… and unfortunate for us who like data in our apps. thanks, daveC

I saw a feature request come through. That’s great because that’s the starting point. 

To help me understand the context, are you looking to build a mobile app or a desktop app?

Is your MySQL server public facing? That is:  can one connect to port 3306 from any computer?

Thanks

Rob

rob, thanks for the reply. primarily mobile apps with remote MySQL database connection via 3306 like port, but I have a proprietary connection scheme for security but that shouldn’t interfere, I do use 3306 for testing though, so something like luasql would be a big help in getting apps to work, then the port would be easy. thanks again.

@davidjcantera, no apps natively connect to MySQL if they do that is a seriously bad implementation of a database layer as a database should always (without exception) reside behind an application layer.  Otherwise people will simply port scan your server and find a MySQL instance responding and they will have a field day!

If your app can natively connect to a MySQL instance then so can anyone else and rest assured there are thousands of idiots that spend their life trying to find insecure instances to take down/corrupt just for kicks.

DBs should be hidden behind firewalls and only accessible by accessing some form of web service with token authentication served via https.

hmmm… I wonder why MySQL wrote this in their docs…  https://dev.mysql.com/doc/refman/5.6/en/using-secure-connections.html

https://dev.mysql.com/doc/refman/5.6/en/secure-connections.html