Game Development Community

dev|Pro Game Development Curriculum

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.

//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

About the author

Recent Blogs

• Attention span.
Page«First 1 2 Next»
#21
07/09/2008 (7:05 am)
@All
Hi,
nice ressource, work fine on VS2008.

My problem, i 'm building a linux dedicated server on Debian, and this ressource mean to be only for Windows.

Someone have an idea, how to use this code on Linux box?

thanks
#22
07/16/2008 (9:31 am)
If you get a huge number of compiler errors (WS2DEF.H and WINSOCK2.H) and you are using Visual C++ 2008 (9.0) Express under Windows XP, then you should try to include winsock.h instead of winsock2.h in fimysql.h.
You don't really use the extra stuff winsock2.h has to offer, such as IPv6 or Bluetooth for mySQL anyway - to my best knowledge. At least this is how I managed to solve my 160 compiler errors, and it works like a charm!
#23
07/16/2008 (12:14 pm)
Thanks for that info Konrad, I was ready to throw myself out a window over those errors.

Edit: I'm having trouble with the actual connect() method - I get a MySQL Error about handshaking which appears to be due to the client being too outdated for the server. Is this just a question of obtaining more recent mysql library files and re-compiling with those? Awesome resource, though.

DoubleEdit: Looks like the 'bad handshake' error was caused since i was using the setupEnv() method which defalts the flag_compress and flag_ssl to 1, despite me entering 0 as the value. I guess this is a bug.
#24
11/09/2008 (6:04 pm)
If anyone is still getting the winsock.h or winsock2.h error. Try downloading the Platform SDk from microsoft the lib is included with this. Just trying to help. This fixed my compile error.

*note: If you have express the libs do not come with it. Install Windows SDK then copy the libs and includes to the VC folder for express.
#25
02/17/2009 (8:09 pm)
I see that there is a lib directory, is there anyway to make this work on mac? I'm not really sure how library files work.......Thx.
#26
03/17/2009 (1:21 am)
Good :)
#27
05/02/2009 (4:13 pm)
G'day, great resource.
Me and my colleague seem to be having some errors. When we try to connect to the server, it says the SQL server has gone away. We've contacted our web masters, yet we are using the right domain name & IP. The code I'm using:
function ZWAuth_Login(%user,%pass)
{
%sql = new Mysql();
%sql.host = "202.191.62.230";
%sql.port = 0;
%sql.user = "user";
%sql.pwd = "pass";
%sql.flag_compress = false;
%sql.flag_ssl = false;
%sql.db = "database";
%connected = %sql.connect();
}
Yet it produces the following errors:
MYSQL ERROR: Can't connect to mysql server on "202.191.62.230" (10060)
If you could help me in this matter I would be greatful.

Cheers
#28
05/05/2009 (5:59 pm)
@Zack Corr

I haven't tried this resource but i am about to....
but you should set your %sql.port = 3306;


as that is the default port for mysql.
also make sure that the user + pwd + db are correct for the db you are trying to connect to.

-jim
#29
09/08/2009 (8:30 am)
Who even knows if this resource is still valid, time to check.
#30
09/10/2009 (3:49 am)
Getting errors:

once calling the function by consol

Unable to instantiate non-conobject class MySQL


then it gives me error of each line...

Unable to find object: "0" attempting to call function 'validatesettings' , 'close' and all of those.
#31
10/05/2009 (5:13 pm)
Robert: I am attempting to implement this under T3D. I finally got the files all in place and got a clean compile, but now I'm getting the same problem you are - "Unable to find object... etc."

Were you able to find a resolution to this?

*update* I got it to work - I was trying stuff in the console when I got that error. I made a .cs file and put that code in and it worked fine.

I can verify this resource works with T3D 1.0 :)
#32
12/13/2009 (10:40 am)
Did you have to change much to get it working with T3D?
#33
12/19/2009 (1:41 pm)
Made a quick video showing how to get everything setup in visual studio to correctly compile.
Should also apply to other versions of torque but the file structure may vary.

ryth.net/T3D_MySQL_Vid.rar
#34
02/25/2010 (12:52 am)
@henry Garle The video is not clear.could you please give the clear video closely.Is there any other video tutorial upload in youtube like sites.

#35
02/26/2010 (11:56 pm)
Is it possible to call C++ function from torque

%mysql= new MySQL();

the above commmand not works in torque.

when i execute the command i am receiving an error

Unable to instantiate non-conobject MySQL()

by torque scripting how we can call C++ functtions.

is it we have to use scriptObject() command like that..

how we can call the c++ functions from torque...

#36
03/02/2010 (5:00 pm)
@cloudfire, the easiest way to get this resource to work is to have a valid Torque license which would get you source code access otherwise you are out of luck on this one....
#37
01/07/2012 (4:56 pm)
Ran into a problem where the engine would crash when more than one item was returned by a query. The issue has to do with how MySQL handles pointer to the MYSQL_ROW data structure. See this post for discussion and a solution: www.garagegames.com/community/forums/viewthread/127637
Page«First 1 2 Next»