How can I connect to MySql ?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
gal050
Prole
Posts: 2
Joined: Wed Jul 10, 2013 11:13 am

How can I connect to MySql ?

Post by gal050 »

I looked all over the internet and I couldn't find a way to connect to an MySql and read/write data from there.
Is that even possible to do in LOVE,Lua ?
If so could somebody send me over the files that needed to do that ?

Thank you all.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How can I connect to MySql ?

Post by raidho36 »

Must be hard to research things without being able to arrange your search query right.

5 seconds in google. http://www.keplerproject.org/luasql/
Last edited by raidho36 on Mon Jul 29, 2013 5:32 pm, edited 1 time in total.
User avatar
jasonisop
Citizen
Posts: 93
Joined: Thu Jun 21, 2012 1:35 am

Re: How can I connect to MySql ?

Post by jasonisop »

raidho36 wrote:Must be hard to live without being able to arrange your search query right.
Why do you have to be such an asshole? He obviously didnt search correctly, but you dont have to be an ass about it. Your comments are not welcoming, and discourging to new users to this forum. I also will request that if i post a topic that you do not respond to it, i dont want your opinions even if they are correct.

There is also http://love2d.org/forums/viewtopic.php?f=5&t=38486 for using sqlite in love.
User avatar
jasonisop
Citizen
Posts: 93
Joined: Thu Jun 21, 2012 1:35 am

Re: How can I connect to MySql ?

Post by jasonisop »

This here shows raidho36's muturity, please do not pm.
Sent: Mon Jul 29, 2013 1:37 pm
From: raidho36
To: jasonisop

Not that I'd wanted to help a pussy like you, who would whine over such a minor things rather than trying to comprehend/ask what have you did wrong, or better yet, just take that part easy, or make a comeback. That's what adults do. At least, in my country.
sorry to de-rail your thead.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How can I connect to MySql ?

Post by raidho36 »

Image
Now THAT is a very helpful and constructive reply. Just why do you think I have sent a PM anyway?
And who's an asshole here, a dude with an attitude or random jerk who mainly came to this thread to bitch about it.

</thisnonsense>
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: How can I connect to MySql ?

Post by Davidobot »

raidho36 wrote:Image
Now THAT is a very helpful and constructive reply. Just why do you think I have sent a PM anyway?
And who's an asshole here, a dude with an attitude or random jerk who mainly came to this thread to bitch about it.

</thisnonsense>
Raidho, no offense or anything and sorry to the OP, but you are being such asshole lately. Just because you want people to figure stuff out on their own, that doesn't mean people will or will not do that. Sometimes you just need to ask someone more experienced to get the right answer, you don't have to be a jackass about it.
Sorry for de-railing the thread.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: How can I connect to MySql ?

Post by Germanunkol »

@gal050, I use mysql in my game. Full code can be found here:

https://github.com/Germanunkol/trainsported
I use luasql as mentioned before in this thread. For an example implementation, check out the databaseLog.lua file:
https://github.com/Germanunkol/trAInspo ... aseLog.lua

With that said, however, you should first get familiar with working with mysql, if you can't even connect to it. Install it on your PC and then try to create a database. Then use Löve/Lua to connect to it (first with the root password) and modify the tables in the database.
Once all of that works, you should create a new mysql user and then use that one from within the Lua script.

What operating system are you using? If you're using linux, I can help you further. If windows, you'll need to find your own tutorials - there's plenty of them, but I have no idea how to use mysql from command line on windows.

And what do you want to use the database for? Are you writing a server for the game?
If you just want to save a game world or something for a single player game you should not use mysql - otherwise every player will need to install mysql before playing your game, which is not a good idea.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
MPQC
Citizen
Posts: 65
Joined: Fri Jun 28, 2013 2:45 pm

Re: How can I connect to MySql ?

Post by MPQC »

Germanunkol wrote:What operating system are you using? If you're using linux, I can help you further. If windows, you'll need to find your own tutorials - there's plenty of them, but I have no idea how to use mysql from command line on windows.
MySQL comes with a terminal which makes it extremely convenient. Login, select the database you want (or create one first), then run any query you want.
gal050
Prole
Posts: 2
Joined: Wed Jul 10, 2013 11:13 am

Re: How can I connect to MySql ?

Post by gal050 »

Thanks to all of you.
I made the database using WampServer, When I load the code it's connecting to the database and finds the table but when I'm trying to take info it's crashing the software.
http://pastebin.com/MSpL8fHr

Thank you all again for the help.
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: How can I connect to MySql ?

Post by Germanunkol »

Have you figured this out yet?
If not, can you tell us the error message you're getting?

Try without the semicolons after the statements (especially the select), the luasql examples don't do it... and it might mean that you're actually executing two statements, I'm not sure.

Otherwise, you can try this:

Code: Select all

function rows (connection, sql_statement)
  local cursor = assert (connection:execute (sql_statement))
  return function ()
    return cursor:fetch()
  end
end

--Here is how the iterator is used:

require "luasql.mysql"
env = assert (luasql.mysql())
con = assert (env:connect"my_db")
for id, name, address in rows (con, "select * from contacts") do
  print (string.format ("%s: %s", name, address))
end

(Taken from here (bottom example).
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 83 guests