Unity with MySQL

Attached is the package that will save and load from MySQL included is a PDF that describes the process of setting up MySQL, adding a table with fields, and adding a view to read from.

Original Release Date 10/10/2010

Updated 10/12/2010
Package now includes both the completed JS and C# scripts to make this work, the PDF is also updated with the JS code.

Updated 2/10/2012
Package updated since the Libraries folder I had contained the DLL’s that worked in 3.4 but not in 3.5, instead they are required now to be in the Plugins folder which really is not a bug but how the system should have originally worked, they simply refined how they truly look for unmanaged libraries.

[attachments removed]

Project now includes both JS and C# (or it should, had issues with the new uploader, let me know if it is missing anything)

I’ve just browsed the pdf and it looks good. I will try it out soon! :slight_smile:

I’m using Unity 2.6 and was wondering if u need diffrent dll files in unity regarding mysql and system.

Regards,

MisterEd

Well, the project is made in U3, so you probably can’t open it in U2.6, the files needed will be the same ones, you just have to pull the ones out of the Unity Editor folders for the local files from
C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity
System.Data.dll and System.Drawing.dll
The other file is located in:
C:\Program Files\MySQL\MySQL Connector Net 6.2.4\Assemblies
MySql.Data.dll

Just make sure you get and download the connector for .net

Can it work with webplayer?:face_with_spiral_eyes:

No because Unity does not allow the MySQL library to be deployed with the package.
I plan on deploying an updated document and package this weekend, but this only works in Mac builds and Windows builds, not web player, not andriod, not iphone, nothing else at the moment until Unity loosens up the security model some, which is highly unlikely.

Sure you really want to make the database globally accessable? (required for mysql to talk to the database)
Its normal that you talk to PHP / ASP.NET layers inbetween that provide you with the informations you need (which can be done through WWW)

1 Like

Thanks!!

I’m trying your package with Unity 3.3 but the javascript return errors : Assets/MySQLJS.js(52,23): BCE0005: Unknown identifier: ‘MySql’.

Have I forget to configure something ? (All .dll are in the Assets/Libraries folder)

Bump! Same as above problem! ^^^ any problem solve?

had a look through the PDF it looked very promising, shame it doesnt work with the web player though, could it not connect to a online database?

Say your database has user info (username, address, char name, CC?, etc)

Do you really want a web player to be able to access that data? Databases usually don’t have very specific ‘permissions’ settings, and you need to have a very good understanding of database design in order to design a system that was ‘safe’ for global access.

For example, at the minimum to set up an ‘authentication’ system, you would need to set up a internally defined procedure in the database’s script language. Then you’d have to set very narrow permissions so that procedure is the only thing visible from the global connection. Then you’d have to consider that most ‘community’ versions of databases tend to not feel OK with 50+ active connections, so you’d hit that threshold pretty quickly with even a mildly successful game.

I would be interested to know how this works. I noticed in the example code that there are some for() loops and the assigning of variables to object variables. I wonder why is this needed, and why couldn’t I just write a simple query statement (SELECT * FROM characters WHERE char_id = ?ID) (I’m assuming that the ? in front of the ID informs the processor this is a variable?)

Thanks.

Seems like a lot more work than just writing a PHP script to process the query and then transfer that to an array for JavaScript to parse though.

I had problems with saving and loading, it came up with some funky errors:
1 : Items in collection : 2
2 : Something about iddemo_table doesn’t have default value at MYSQL really long stuff

Get anyone the mysql dll’s working under unityscript? I can use them with c#, but get only error’s (Namespace ‘MySql.Data.MySqlClient’ not found, maybe you forgot to add an assembly reference? or BCE0005: Unknown identifier: ‘MySql’.)

Attention!!!
The attached file “MySQLDemo.unitypackage (532.3 KB, 603 views)” is a VIRUS!

zumwalt ?!

Thats blurp, its no virus. pushed it through kaspersky and ESET32, no hit, so its pretty surely a false positiv of some half arsed freeware protection (avira or payed viruses like McAfee / norton that claim to be good yet lack enough and even spread fake virus / worms that only they detect)

Hi zumwalt,
how did I fix the problem in JS script??
Assets/MySQLJS.js(50,23): BCE0005: Unknown identifier: ‘MySql’.

It appears that the latest version of Unity has removed the native import of libraries to an extent, more stripping I suppose, this was working in prior versions of Unity 3, but the new public beta, the JS doesn’t work, looks like a regression bug to me. I know the C# version still works but even though the DLL is in the right place from the package, Unity 3.5 public beta does not work with it an Unity Script.

EDIT:
Re-Download the package that or create a folder called Plugins in your asset folder and move all DLL’s that are in the Libraries folder to the Plugins folder, wabam, should now work. All these itterations later and they make a change where the unmanaged AND managed are now required to be in the Plugins folder, it used to be that you could put them in your own folders exclusive of the Plugins folder to the bug was really that the unmanaged AND managed libraries were allowed to be anywhere and they fixed that. All DLL’s need to be inthe Plugins folder it looks like for 3.5