### Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

Entire forum
MUSHclient
General
mysql connections
Username: Home  |  Users  |  Search  |  FAQ Register forum user name Forgotten password?

mysql connections

It is now over 60 days since the last post. This thread is closed.      Refresh page

Pages: 1 2

Posted by Lilbopeep   USA  (42 posts)   bio
Date Mon 17 Aug 2009 03:05 AM (UTC)
Message
 hey everyone! okay, so I have a server with mysql on it, but I'm having trouble getting any of the scripts work with it. I plan on creating a database to store multiple things, and use alias' to create queries / modifications to the different tables. The catch is I plan to create a plug-in so other people can access and possibly modify. From there, I hope to move the output into a miniwindow, but plan on just noting it into the output for now. I don't know one scripting language from the other, but with an example I can generally figure out what's happening - so to that end I am open to using any one of the many scripting languages to build this. For starters.. What do I need to do first? Many of the database plug-ins or scripts require additional dll's, but I don't know if anything has changed with my version (4.43). From there, How do I connect to my database? Let's say I have a database called test with a table called areas and fields name level directions... see where I am going? Simple is best, for me, and any help is appreciated! thanks! ,.~'~.,Dance Magic Dance,.~'~., top

 Posted by Blainer   (191 posts)   bio Date Reply #1 on Mon 17 Aug 2009 03:32 AM (UTC) Message

Posted by Lilbopeep   USA  (42 posts)   bio
Date Reply #2 on Mon 17 Aug 2009 03:55 AM (UTC)
Message
 Oh, that's going to be very helpful once I figure out how to connect to my database, thank you! ,.~'~.,Dance Magic Dance,.~'~., top

Posted by Blainer   (191 posts)   bio
Date Reply #3 on Mon 17 Aug 2009 04:11 AM (UTC)
Message
 This one might help. http://www.gammon.com.au/forum/?id=5983 I used the info above to make a plugin that connects to a public database on the internet.  assert (package.loadlib ("mysql.dll", "luaopen_luasql_mysql")) () env = assert (luasql.mysql()) con = assert (env:connect ("adatabase", "guest", "password", "adatabase.org"))  top

Posted by Twisol   USA  (2,257 posts)   bio
Date Reply #4 on Mon 17 Aug 2009 05:51 AM (UTC)
Message
 To be honest, I don't think it's a good idea to access your database directly like this, it opens up a lot of ways for people to do malicious stuff. What I'd do is get the LuaSocket library (which Nick mentioned once or twice he might be adding to MUSHclient anyways), and use its HTTP protocol extension to send GET/POST messages to the server. The server can then take some action (verify incoming data for one) and return a proper response. 'Soludra' on Achaea Blog: http://jonathan.com/ GitHub: http://github.com/Twisol top

Posted by Nick Gammon   Australia  (21,555 posts)   bio   Forum Administrator
Date Reply #5 on Mon 17 Aug 2009 05:58 AM (UTC)
Message
 The other question is, is this for you alone? Then SQLite might be easier, and you just have a disk file on your disk. See my recent posts about http://mushclient.com/sql and http://mushclient.com/db. As for the malicious stuff, he has a point, but with user access control it might be reasonably safe. And you could consider adding referential integrity checks to the database. - Nick Gammon www.gammon.com.au, www.mushclient.com top

Posted by Lilbopeep   USA  (42 posts)   bio
Date Reply #6 on Mon 17 Aug 2009 06:13 AM (UTC)
Message
 Malicious how? Only people I "trust" would be given credentials to log in and access information. It wouldn't be a public database. A secondary benefit is the potential to do similar things with a database through the website, and from what i've seen php and mysql seem to be the de facto way to handle this, so it's perfect for me, unless I am missing something crucial? ,.~'~.,Dance Magic Dance,.~'~., top

Posted by Nick Gammon   Australia  (21,555 posts)   bio   Forum Administrator
Date Reply #7 on Mon 17 Aug 2009 06:21 AM (UTC)
Message
 No, you're fine. The post Blainer mentioned at http://www.gammon.com.au/forum/?id=5983 should help you. If something goes wrong, please be specific about what it is. For example, the database might need 'grant' access to give you remote access. Something like (in SQL):  GRANT ALL ON your_database.* TO Lilbopeep@wherever_you_are IDENTIFIED BY "yourpassword";  - Nick Gammon www.gammon.com.au, www.mushclient.com top

Posted by Lilbopeep   USA  (42 posts)   bio
Date Reply #8 on Mon 17 Aug 2009 06:39 AM (UTC)
Message
 okay, well my first option was just to try to load the DLL. Seemed simple enough -  [string "Alias: "]:2: Function 'package.loadlib' disabled in Lua sandbox - see MUSHclient global preferences stack traceback: [C]: in function 'error' [string "Sandbox"]:39: in function 'loadlib' [string "Alias: "]:2: in main chunk  So I checked global preferences, saw a little box that said 'allow DLL's to be loaded' and figured that was my issue, but checking said box didn't work, I still got the same error. my alias is simply -  -- load the MySQL dll assert (package.loadlib ("mysql.dll", "luaopen_luasqlmysql")) ()  with send to Script selected. ,.~'~.,Dance Magic Dance,.~'~., top

Posted by WillFa   USA  (525 posts)   bio
Date Reply #9 on Mon 17 Aug 2009 07:07 AM (UTC)
Message
 IF you're going to be doing stuff with a database, you definitely want to start using the script file and not just trigger's send to boxes... Also, in Lua 5.1, loadlib is deprecated. If you have luasql downloaded, you can just  require "luasql.mysql"  Installing luasql is as simple as downloading it, and then setting a variable to point to the directory. Press the Windows key + Pause (it's in the top right corner) go to the advanced tab, click environment variables, and add a system variable for:  LUA_CPATH=.\?.dll;C:\Lua\5.1\clibs\?.dll;C:\path\to\dled\file\?.dll  So if you wanted, you could make a subdirectory under Mushclient's LUA directory named luasql, and put the mysql.dll in there...  LUA_CPATH=.\?.dll;C:\Lua\5.1\clibs\?.dll;C:\program files\mushclient\lua\?.dll;  Restart Mushclient, press CTRL+SHIFT+H to bring up the script file (it will yell at you to set one up if you haven't) and require away... top

Posted by Lilbopeep   USA  (42 posts)   bio
Date Reply #10 on Mon 17 Aug 2009 07:23 AM (UTC)
Message
 well, I'm not opposed to going with something like this, but honestly it doesn't make any sense :( I mean, it seems like -another- way to do it, but none of these links have gotten me past step 1, despite following them almost exactly. Moving something to a script file seems secondary to just getting /some/ progress, and I'll get back to it later. I don't even know what luasql.mysql is. In my MUSHclient folder I have lua5.1.dll, libmysql.dll, and mysql.dll. I believe I added the last two myself from instructions on another page. I've done this easily with PHP before -   Is it this much more difficult? Is PHPscript the same as PHP? ,.~'~.,Dance Magic Dance,.~'~., top

Posted by WillFa   USA  (525 posts)   bio
Date Reply #11 on Mon 17 Aug 2009 07:44 AM (UTC)
Message
 Step By Step: 1. Download LUASQL from the kepler project: http://luaforge.net/frs/download.php/2683/luasql-2.1.1-mysql50-win32-lua51.zip PHP was designed for dynamic webpage generation, it was assumed you'll be talking to a database so it's built in. I guarantee you'll have an easier time getting MC to talk to MySql than you will getting PHP/Apache to handle telnet negotiation. :) 2. Extract that zip to C:\Program Files\Mushclient\Lua. There should now be a C:\Program Files\Mushclient\Lua\Luasql\MySql.dll (you can probably move the one you already got to that directory) 3. Press Ctrl+Alt+G and make sure you can load dll's (you have already done this.) 4. Press CTRL+SHIFT+6 and configure Mushclient to have a script file. I'm assuming you're leaving the scripting language as Lua, and you can put the script file where ever you like. (My Documents?). Click OK. 5. Press CTRL+SHIFT+H (Game menu -> Edit Script File...) and start coding! 6. for example:  require "luasql.mysql" sourcename = "something to connect to my database" username = "me" password = "swordfish" hostname = "mysql.internet.org" port = "4314" env = luasql.mysql() db = env:connect(sourcename, username, password, hostname, port) cursor = db:execute("SELECT theanswer FROM mybutt")  7. read http://www.keplerproject.org/luasql/manual.html for more information on working with Luasql. It's not that difficult, but you're biting off a rather large chunk for someone that "doesn't know one scripting language from another". top

Posted by Nick Gammon   Australia  (21,555 posts)   bio   Forum Administrator
Date Reply #12 on Mon 17 Aug 2009 07:45 AM (UTC)
Message
 Quote: So I checked global preferences, saw a little box that said 'allow DLL's to be loaded' and figured that was my issue, but checking said box didn't work, I still got the same error. Slow down a minute. You are on the right track here. After checking that box you need to reload the script file to get the new sandbox processed. Just closing the world and re-opening it will do that, but there is a menu item as well. It *does* work. :) - Nick Gammon www.gammon.com.au, www.mushclient.com top

Posted by Lilbopeep   USA  (42 posts)   bio
Date Reply #13 on Mon 17 Aug 2009 08:23 AM (UTC)

Amended on Mon 17 Aug 2009 08:35 AM (UTC) by Lilbopeep

Message
 Quote: Slow down a minute. You are on the right track here. After checking that box you need to reload the script file to get the new sandbox processed. Just closing the world and re-opening it will do that, but there is a menu item as well. It *does* work. :) But it doesn't. The box is clearly checked. I've gone as far as closing / reopening the world to closing and opening MUSHclient itself. I have an alias that is  -- load the MySQL dll assert (package.loadlib ("mysql.dll", "luaopen_luasqlmysql")) ()  and when I type the alias I get the same message  [string "Alias: "]:2: Function 'package.loadlib' disabled in Lua sandbox - see MUSHclient global preferences stack traceback: [C]: in function 'error' [string "Sandbox"]:39: in function 'loadlib' [string "Alias: "]:2: in main chunk  I mean, if we ignored everything else I wanted to do and started off with the proverbial baby-step, this seems to be the first one; including the mysql.dll file. And thanks for all the responses, btw! Such a lovely client. ,.~'~.,Dance Magic Dance,.~'~., top

Posted by Twisol   USA  (2,257 posts)   bio
Date Reply #14 on Mon 17 Aug 2009 08:29 AM (UTC)

Amended on Mon 17 Aug 2009 08:35 AM (UTC) by Twisol

Message
 You need to trust both the world and whatever plugin you're putting it in (if any). For the former, use ctrl+I and run "print(GetWorldID())" to get your world's ID. For the latter, it's in the plugin's XML near the top. To add these to the trusted list, go to File -> Global Preferences and hit the Lua tab. Look for a line that starts with "local trusted_worlds = {", and add a new line with your world ID. I'll paste an example below. Do the same for your plugin (if any), but in the "local trusted_plugins" table.  local trusted_worlds = { -- ["a4a1cc1801787ba88cd84f3a"] = true, --example world ["your world ID here"] = true } -- end of trusted_worlds -- Plugin IDs of plugins we trust - add your plugins to the table local trusted_plugins = { -- ["03ca99c4e98d2a3e6d655c7d"] = "Chat", --example plugin ["your plugin ID here"] = true } -- end of trusted_plugins  It's annoying and I've posted about it elsewhere, I'm glad I'm not the only one who got caught by it. (EDIT: I mean the fact that you have to trust the plugin AND the world to get a plugin to work properly. Never mind that it's an annoying process to look for and add the entry/entries in the first place...) 'Soludra' on Achaea Blog: http://jonathan.com/ GitHub: http://github.com/Twisol top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.

16,953 views.

This is page 1, subject is 2 pages long: 1 2

It is now over 60 days since the last post. This thread is closed.      Refresh page

Go to topic:           Search the forum

top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

Comments to: Gammon Software support
Forum RSS feed ( https://gammon.com.au/rss/forum.xml )