MySQL integration for TGE/TGEA
by Henry Garle · 10/08/2007 (10:22 am) · 37 comments
This is based off an old resource that used a 2002 build of the lib which leaves it open to security holes, lack of features and having t owork around its "quirks". The file that is attatched has all the required files needed to install MySQL and i will guide you step by step on how to do it.
Eugh .. file size limit ... Here is the link to the files.
ryth.net/MySQL.rar
First download the file and open it up.
Extract the file into your main directory (F.E Z:Tourque_1_0_3)
You need to add the lib(Z:Tourquelibmysqllib)
and include (Z:Tourquelibmysqlinclude)
folder to your project (If your not sure how there is alot of info around)
Next, add the folder and all of its contents z:tourqueenginegamemysql to your project.
Compile!
Here is an example of how to use MySQL within your project.
Short video explaining how to setup your visual studio in order to compile with MySQL.
ryth.net/T3D_MySQL_Vid.rar
Eugh .. file size limit ... Here is the link to the files.
ryth.net/MySQL.rar
First download the file and open it up.
Extract the file into your main directory (F.E Z:Tourque_1_0_3)
You need to add the lib(Z:Tourquelibmysqllib)
and include (Z:Tourquelibmysqlinclude)
folder to your project (If your not sure how there is alot of info around)
Next, add the folder and all of its contents z:tourqueenginegamemysql to your project.
Compile!
Here is an example of how to use MySQL within your project.
//All information is stored in local variables (%) So that no one can gain information via the console.
function MySQL()
{
%mysql= new MySQL();
%mysql.host= "localhost"; // default: "localhost"
%mysql.port= 0; // default: 3306
%mysql.user= "root"; // No default
%mysql.pwd= ""; // default: ""
%mysql.flag_compress= false; // default: false
%mysql.flag_ssl= false; // default: false
%mysql.db= "news"; // No default
%mysql.ValidateSettings(); // optional
%mysql.Connect();
%mysql.Query ("SELECT * FROM news");
%result= %mysql.StoreResult();
for (%i= 0; %i< %mysql.NumRows (%result); %i++)
{
%mysql.FetchRow (%result);
%id= %mysql.GetRowCell (%result, "Index");
%date= %mysql.GetRowCell (%result, "Date");
echo (%id, " --- ", %date);
}
%mysql.FreeResult (%result);
%mysql.Close();
}
MySQL();Short video explaining how to setup your visual studio in order to compile with MySQL.
ryth.net/T3D_MySQL_Vid.rar
#2
10/08/2007 (5:06 pm)
Great! Good to have updates on this type of resources.
#3
As a MySQL OEM developer by day, I had a conversation with thy guys over at MySQL about a year ago about something like this and their response was basically, "We don't want to support MySQL in a low-end software project that is non-GPL, go use someone else's database, we really don't want your business, and this isn't a model we are going to support anytime soon."
PostgreSQL, SQL Server Express, Oracle Express, Blackfish SQL (if you're a Borland/Codegear developer), and others of the BSD license or free limited version variety are a much better fit with the Torque licensing model.
10/12/2007 (5:40 am)
Great work here. Sorry to break your bubble, but unfortunately, using MySQL for the torque game engine is totally unpractical on the licensing side. This is because you have to open source the game engine via the GPL (which Torque licensing doesn't allow), or you have to purchase a commercial MySQL license, currently about $600/copy for OEMs (yeah, who's gonna purchase a game, any game, at $600/copy when they could just as easily buy a new console). As a MySQL OEM developer by day, I had a conversation with thy guys over at MySQL about a year ago about something like this and their response was basically, "We don't want to support MySQL in a low-end software project that is non-GPL, go use someone else's database, we really don't want your business, and this isn't a model we are going to support anytime soon."
PostgreSQL, SQL Server Express, Oracle Express, Blackfish SQL (if you're a Borland/Codegear developer), and others of the BSD license or free limited version variety are a much better fit with the Torque licensing model.
#4
10/14/2007 (9:48 am)
Well, that being said if this is being used in an MMO model then if you use a master server you could use 1 licence. Clients send commands for into to the server, the location server to the database server. I wasnt aware of the licencing issues though. Oh well, if people are serious about using MySQL they could buy the 1 licence when needed upon release. A one off payment of $600 for a setup of an MMO is not alot in the grand scale of things (Unless it breaches the licence in some way?)
#5
10/16/2007 (11:43 pm)
You are absolutely correct Henry. MySQL would work fine for an MMO, and since you aren't releasing the code that integrated with MySQL to anyone, you could use a GPL version of MySQL.
#7
Although they aren't willing to give it away free in a commercial product, he said they are willing to model their licensing model after your commerical product licensing model and make it a raw % of sales if you are willing to commit to some minimal volume, like say, a 1,000 copies. Hence, if you're selling your product for $50/copy, they might be willing to let you embed MySQL for $5/copy if you commit to at least selling 1,000 copies, and hence would pay them at least $5k. (Of course these numbers are just guesses, you'd have to talk directly to MySQL to get an actual quote & license agreement.)
It does however, make MySQL a definate possibility for use in the game arena, especially since it can support many gigs of data and has a smaller footprint than some of the other databases.
Here's a link to a webinar in 3 weeks where they compare themselves with Microsoft SQL Server Express.
http://www.mysql.com/news-and-events/web-seminars/display-69.html
10/25/2007 (1:47 pm)
I just spoke with my MySQL representative today about embedding it in smaller commercial products. They appear to be getting some serious pressure to compete with Microsoft SQL Server Express, Oracle Express, and other open source databases in this arena.Although they aren't willing to give it away free in a commercial product, he said they are willing to model their licensing model after your commerical product licensing model and make it a raw % of sales if you are willing to commit to some minimal volume, like say, a 1,000 copies. Hence, if you're selling your product for $50/copy, they might be willing to let you embed MySQL for $5/copy if you commit to at least selling 1,000 copies, and hence would pay them at least $5k. (Of course these numbers are just guesses, you'd have to talk directly to MySQL to get an actual quote & license agreement.)
It does however, make MySQL a definate possibility for use in the game arena, especially since it can support many gigs of data and has a smaller footprint than some of the other databases.
Here's a link to a webinar in 3 weeks where they compare themselves with Microsoft SQL Server Express.
http://www.mysql.com/news-and-events/web-seminars/display-69.html
#8
11/04/2007 (11:54 am)
i get the error that it cant fint wisock2.h Why?
#9
Does this bypass the licensing and make it then GPL compliant by making the php scripts open source?
11/14/2007 (8:09 am)
What about having your game use httpObject() and send a command to execute a php script on a web server? Just like this GG resource www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4085Does this bypass the licensing and make it then GPL compliant by making the php scripts open source?
#10
compiling with vs2005 using a clean install of torque and the files provided.
1>Linking...
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function "public: __thiscall MySQL::MySQL(void)" (??0MySQL@@QAE@XZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_free_result@4 referenced in function "protected: void __thiscall MySQL::FreeResult(struct st_mysql_res *)" (?FreeResult@MySQL@@IAEXPAUst_mysql_res@@@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_error@4 referenced in function "public: bool __thiscall MySQL::Connect(void)" (?Connect@MySQL@@QAE_NXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function "public: bool __thiscall MySQL::Connect(void)" (?Connect@MySQL@@QAE_NXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function "public: void __thiscall MySQL::Close(void)" (?Close@MySQL@@QAEXXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_query@8 referenced in function "public: bool __thiscall MySQL::Query(char const *)" (?Query@MySQL@@QAE_NPBD@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_store_result@4 referenced in function "public: int __thiscall MySQL::StoreResult(void)" (?StoreResult@MySQL@@QAEHXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_num_rows@4 referenced in function "public: int __thiscall MySQL::NumRows(int)" (?NumRows@MySQL@@QAEHH@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_row@4 referenced in function "public: bool __thiscall MySQL::FetchRow(int)" (?FetchRow@MySQL@@QAE_NH@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_num_fields@4 referenced in function "public: char const * __thiscall MySQL::GetRowCell(int,int)" (?GetRowCell@MySQL@@QAEPBDHH@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_field_direct@8 referenced in function "public: char const * __thiscall MySQL::GetRowCell(int,char const *)" (?GetRowCell@MySQL@@QAEPBDHPBD@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_field_count@4 referenced in function "public: int __thiscall MySQL::NumFields(void)" (?NumFields@MySQL@@QAEHXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_insert_id@4 referenced in function "public: int __thiscall MySQL::InsertID(void)" (?InsertID@MySQL@@QAEHXZ)
1>../example/torqueDemo_DEBUG.exe : fatal error LNK1120: 13 unresolved externals
11/26/2007 (12:00 pm)
having some trouble compiling this code.... heres waht i get when i try to compile please please help........compiling with vs2005 using a clean install of torque and the files provided.
1>Linking...
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function "public: __thiscall MySQL::MySQL(void)" (??0MySQL@@QAE@XZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_free_result@4 referenced in function "protected: void __thiscall MySQL::FreeResult(struct st_mysql_res *)" (?FreeResult@MySQL@@IAEXPAUst_mysql_res@@@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_error@4 referenced in function "public: bool __thiscall MySQL::Connect(void)" (?Connect@MySQL@@QAE_NXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function "public: bool __thiscall MySQL::Connect(void)" (?Connect@MySQL@@QAE_NXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function "public: void __thiscall MySQL::Close(void)" (?Close@MySQL@@QAEXXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_query@8 referenced in function "public: bool __thiscall MySQL::Query(char const *)" (?Query@MySQL@@QAE_NPBD@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_store_result@4 referenced in function "public: int __thiscall MySQL::StoreResult(void)" (?StoreResult@MySQL@@QAEHXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_num_rows@4 referenced in function "public: int __thiscall MySQL::NumRows(int)" (?NumRows@MySQL@@QAEHH@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_row@4 referenced in function "public: bool __thiscall MySQL::FetchRow(int)" (?FetchRow@MySQL@@QAE_NH@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_num_fields@4 referenced in function "public: char const * __thiscall MySQL::GetRowCell(int,int)" (?GetRowCell@MySQL@@QAEPBDHH@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_field_direct@8 referenced in function "public: char const * __thiscall MySQL::GetRowCell(int,char const *)" (?GetRowCell@MySQL@@QAEPBDHPBD@Z)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_field_count@4 referenced in function "public: int __thiscall MySQL::NumFields(void)" (?NumFields@MySQL@@QAEHXZ)
1>mysql.obj : error LNK2019: unresolved external symbol _mysql_insert_id@4 referenced in function "public: int __thiscall MySQL::InsertID(void)" (?InsertID@MySQL@@QAEHXZ)
1>../example/torqueDemo_DEBUG.exe : fatal error LNK1120: 13 unresolved externals
#11
\lib\opt\ directory.
11/26/2007 (12:25 pm)
It looks like you need to link in libmysql.lib It's usually found in the
#12
11/26/2007 (12:27 pm)
well i added the path for includes and libraries...... im trying to figure out how to add the dll or lib file in vs2005... must be a noob question.... lol.
#13
11/26/2007 (1:42 pm)
In Visual Studio 2005: Select the project in the project explorer. Then from the main menu on the top select Project->Properties Browse to Configuration Properties->Linker->Input. Put the full path to the libmysql.lib in the Additional Dependancies property along with all of the other libraries. (You'll want to do this for both the release and debug versions.)
#14
01/19/2008 (9:32 pm)
Nice although i dont see anything that escapes the query string meaning if it involves user input this module is vulnerable to SQL Injection attacks. Check out the original comments here http://garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5286 I posted some code that offers a solution to this.
#15
LINK : fatal error LNK1181: cannot open input file 'E:\TGE_1_5_2\lib\mysql\lib.obj'
Anyone have any clues what I'm doing wrong?
EDIT: Bonehead mistake, I had included the pathway...
E:\TGE_1_5_2\lib\mysql\lib\opt
And not the file name...
E:\TGE_1_5_2\lib\mysql\lib\opt\libmySQL.lib
Compiles fine now.
04/14/2008 (10:24 am)
I've followed this through twice very carefully and I keep getting the following error...LINK : fatal error LNK1181: cannot open input file 'E:\TGE_1_5_2\lib\mysql\lib.obj'
Anyone have any clues what I'm doing wrong?
EDIT: Bonehead mistake, I had included the pathway...
E:\TGE_1_5_2\lib\mysql\lib\opt
And not the file name...
E:\TGE_1_5_2\lib\mysql\lib\opt\libmySQL.lib
Compiles fine now.
#16
This does work perfectly when used through localhost. Thanks for a great resource and thanks to anyone who can offer some advice on connecting remotely.
04/14/2008 (2:00 pm)
Has anyone else tried this with a remote server instead of localhost? I cant seem to get it to connect to the database when using an IP address instead of "localhost". I've made sure ports are forwarded through the router and even completely turned off the firewalls and still can't get a connection. This does work perfectly when used through localhost. Thanks for a great resource and thanks to anyone who can offer some advice on connecting remotely.
#17
05/12/2008 (6:46 am)
nounstand. i want setup with picture for lern
#18
1>winDispatch.cpp
1>..\..\..\..\..\engine\source\windowManager\win32\winDispatch.cpp(436) : error C2065: 'PM_QS_POSTMESSAGE' : undeclared identifier
...and...
1>popupMenuWin32.cpp
1>..\..\..\..\..\engine\source\platformWin32\menus\popupMenuWin32.cpp(113) : error C2065: 'MENUINFO' : undeclared identifier
1>..\..\..\..\..\engine\source\platformWin32\menus\popupMenuWin32.cpp(113) : error C2146: syntax error : missing ';' before identifier 'mi'
1>..\..\..\..\..\engine\source\platformWin32\menus\popupMenuWin32.cpp(113) : error C2065: 'mi' : undeclared identifier
1>..\..\..\..\..\engine\source\platformWin32\menus\popupMenuWin32.cpp(114) : error C2228: left of '.cbSize' must have class/struct/union
1> type is ''unknown-type''
...14 errors total. I have re-started and followed the instructions from scratch 3 times now with identical results. I'm posting here in hopes someone with a little more experience with these matters can say "Aha!" you've screwed up X,Y, or Z in the process... I suspect that 1 or more of the libraries or include directories I've connected is not appropriate for this project and is being used instead of the correct resource. If I try to exclude particular include directories or libraries then I end up with either winsock2.h missing or mysql.h missing errors. Copying mysql.h directly into the project yields interesting results, the project compiles but I get mysql.h missing errors at runtime. So it may be obvious that I'm a little over my head here but I am trying very hard to resolve this on my own and to learn, any nudge in the right direction would be very much appreciated.
05/29/2008 (12:16 pm)
I am somewhat at a loss here. Using Torque 1.7 w/AFX also tried without, VC++ 2005, MYSQL 5.0 (working fine on machine) I can't seem to get MySQL integrated into this project. I've connected the various libraries and include directories from this resource, the Microsoft SDK, and MySQL to the VC project and I end up with compile errors from files I haven't touched such as...1>winDispatch.cpp
1>..\..\..\..\..\engine\source\windowManager\win32\winDispatch.cpp(436) : error C2065: 'PM_QS_POSTMESSAGE' : undeclared identifier
...and...
1>popupMenuWin32.cpp
1>..\..\..\..\..\engine\source\platformWin32\menus\popupMenuWin32.cpp(113) : error C2065: 'MENUINFO' : undeclared identifier
1>..\..\..\..\..\engine\source\platformWin32\menus\popupMenuWin32.cpp(113) : error C2146: syntax error : missing ';' before identifier 'mi'
1>..\..\..\..\..\engine\source\platformWin32\menus\popupMenuWin32.cpp(113) : error C2065: 'mi' : undeclared identifier
1>..\..\..\..\..\engine\source\platformWin32\menus\popupMenuWin32.cpp(114) : error C2228: left of '.cbSize' must have class/struct/union
1> type is ''unknown-type''
...14 errors total. I have re-started and followed the instructions from scratch 3 times now with identical results. I'm posting here in hopes someone with a little more experience with these matters can say "Aha!" you've screwed up X,Y, or Z in the process... I suspect that 1 or more of the libraries or include directories I've connected is not appropriate for this project and is being used instead of the correct resource. If I try to exclude particular include directories or libraries then I end up with either winsock2.h missing or mysql.h missing errors. Copying mysql.h directly into the project yields interesting results, the project compiles but I get mysql.h missing errors at runtime. So it may be obvious that I'm a little over my head here but I am trying very hard to resolve this on my own and to learn, any nudge in the right direction would be very much appreciated.
#19
Setting "_WIN32_WINNT" tells the windows headers what version of windows to target with your build. 0x0400 means Windows NT. With the latest sdk this is no longer a valid option. Instead you can use 0x0500 which means Windows 2000 and is still valid.
hth
06/06/2008 (11:52 am)
@Robert - Try changing all "_WIN32_WINNT" definitions in your Torque installation from 0x0400 to 0x0500. On mine there is one in winDispatch.cpp and one in platformWin32.h. Setting "_WIN32_WINNT" tells the windows headers what version of windows to target with your build. 0x0400 means Windows NT. With the latest sdk this is no longer a valid option. Instead you can use 0x0500 which means Windows 2000 and is still valid.
hth
#20
I would never have known to make those changes, they worked!! Thank you!! Now I'm back to grappling with a problem where the linker is not recognizing or using libmysql.lib even though I have set the library paths correctly. I made this issue go away once before so I'm pretty sure I can figure it out.
Thanks again for taking the time to help me out, I can't thank you enough.
06/10/2008 (12:21 pm)
@MikeI would never have known to make those changes, they worked!! Thank you!! Now I'm back to grappling with a problem where the linker is not recognizing or using libmysql.lib even though I have set the library paths correctly. I made this issue go away once before so I'm pretty sure I can figure it out.
Thanks again for taking the time to help me out, I can't thank you enough.

Torque 3D Owner Taras (TSK) Anatsko