[help+]Does Construct access SQL Databases?

For questions about using Classic.

Post » Mon May 23, 2011 10:57 pm

Hey Scidave or any other

I'm with a new problem here..

I've made a simple construct game with some of those scripts so my friend could test if he can access my database and add/read from it...
I've changed MySQLdb.connect in inital script to:

db = MySQLdb.connect("MY GLOBAL IP","root","","highscores" )
and I compiled everything selecting the pyc files.
When he tries to test the game, appear an error where it says "host 'his global ip' is not allowedto connect to this MySQL server"
so probably i had to change something to allow remote access to my db.. so I looked for help in google and found that i need to add in my.cnf
bind-address=my_ip and add a comment to skip-networking.
I'm using XAMPP so i've found this file at the mysql folder and the skip-networking was already commented and I added the bind-address=my_localip
but he still had the same error.. so probably it not worked or I'm doing something wrong.. any1 know what it should be??
thanks..
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue May 24, 2011 12:32 am

Hi,

I'm going to need lots more details to troubleshoot this. The bind-network option simply sets which interface your server will listen on (for example if your system had two NICs). So I think the problem is something else. Are you behind a router? Do you have port forwarding enabled? Can he telnet to your server and pull a banner?

You would run WIreshark and have him connect and see if you even see him connecting to your server.

My guess is you are behind a router and he can't connect to your server, but maybe it is a firewall or config issue. Need more detailed error messages as well.

Thanks!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Tue May 24, 2011 12:55 am

Hey scidave, thanks for replying

So, yes, I'm behind a router and have portforwarded the essencial ports already, what ports exacly should I forward? So I can check if there is something left..

About the other stuffs he unfortunaly is sleeping right now so I will be able only to inform about this other questions tomorrow =(
but the error was when he tryed to open the program, appeared a script error saying ''host 'his globalip' was unable to conect to this database" I'll send a pic of it tomorrow with more detailed informations..

But I think it's nothing related to ports cuz times ago I had some private game servers with sql database running here for friends and they always connected..

Maybe is something about the GRANT privileges? I've readed something about it but not sure if could be it, it seems to allow accounts privileges, but they are connecting with the root username, should then I make a new account with some privileges just for remote access?
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue May 24, 2011 11:50 pm

[quote="Guif0DA":1jund01s]Maybe is something about the GRANT privileges? I've readed something about it but not sure if could be it, it seems to allow accounts privileges, but they are connecting with the root username, should then I make a new account with some privileges just for remote access?[/quote:1jund01s]
I think this is probably your problem since you have the ports forwarded.

You want to limit what users can do so they don't dork up your database.

For example you could do the below to allow the user "bar" to do anything on database "foo"
GRANT ALL ON foo.* TO bar@% IDENTIFIED BY PASSWORD;

Ideally, you would create a separate account, as you mentioned, that has less privileges than your root account.

http://dev.mysql.com/doc/refman/5.1/en/ ... users.html
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Wed May 25, 2011 2:47 am

Hey scidave thanks as always for your replies

So.. just before I made that last post I discovered that was the GRANT thing.. I made another acc just for clients to access remotely and with few privileges.. today I tested it with my friend and it all worked! ;D
the problem was that the acc I used to them access was the root one and this acc can only be used localy, from my PC only.. so I made a new one that could be accessed anywhere by adding a % at host ;)
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Wed May 25, 2011 7:54 am

Hey Scidave.. do u have any idea to how make only be possible to use Letters and numbers in a editbox checking with a python script?
tryed using strspn(Editbox.Text, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890")
not even sure if 'strspn' exists in python..

I need to discover the exact string method.. so I could try:
if editbox.text contains only letters and/or numbers it would be okay.

then if the editbox.text have a symbol letter like '%' or '&' it will inform you that it's incorrect.


EDIT: I did ;D
used the strip function to compare with the result
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Thu May 26, 2011 12:40 am

Awesome! Glad to hear things are working good. This is indeed a great thread to learn database access. :wink:
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sun May 29, 2011 8:27 pm

Hey scidave, I'm trying to get simple results from the database, right now I'm executing a query and after that I use fetchone() function to get the result, but the result instead to be just a simple string like in the database, have some more digits.. I'll try to explain better with an example:
In a database called 'TEST' there is a username called TESTER
so I execute a query to get this username and put in a Text object in construct.
the result instead to be just "TESTER" is "('TESTER,')" so after the results I need to remove those other things with a strip function.
Now if I get a result from a value in the database, instead to be just the value(4 for example), it comes with "(4L)"..
so this is my question, is there any way I could just get the exact result from a database without those brackets, etc?
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Sun May 29, 2011 10:33 pm

The results are usually returned as a Tuple or if nothing is available the result will be None. So you should access the result as a Python list.

For example:

[code:3q411di1]
cursor.execute ("SELECT name, category FROM animal")
while (1):
row = cursor.fetchone ()
if row == None:
break
print "%s, %s" % (row[0], row[1])
print "Number of rows returned: %d" % cursor.rowcount
[/code:3q411di1]


You could also retrieve the rows as Python dictionaries to retrieve results by name (and not index):

[code:3q411di1]
cursor.close ()
cursor = conn.cursor (MySQLdb.cursors.DictCursor)
cursor.execute ("SELECT name, category FROM animal")
result_set = cursor.fetchall ()
for row in result_set:
print "%s, %s" % (row["name"], row["category"])
print "Number of rows returned: %d" % cursor.rowcount
[/code:3q411di1]

Hopefully, that was the problem!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sun May 29, 2011 11:01 pm

This while(1) from the first code means what?
it's true?


I'll try it with Construct and see if was what I was looking for..
instead of print I should use SetText right?

Also, what is the difference retrieve as python dictionaries? didn't understood what u meant by index..
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

PreviousNext

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests