[help+]Does Construct access SQL Databases?

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Even if python is installed...by default it wont necessarily recognized "python" on command line.

    The fact that you got an error saying "setuptools not found" suggests you should install setup tools.

    If you don't want to try that you're best bet is an executable build (pick the 2.6 build for 32-bit):

    http://www.codegood.com/archives/4

  • I downloaded the executable build and already installed, now im trying to follow your tutorial

    python_library_quickguide.pdf but can't get to work.. i made the script to import mysqldb and saved it, made then a setup p2exe script:

    from distutils.core import setup
    from pyexpat import *
    import py2exe
    
    setup( console=["mysqldb.py"])[/code:3th9b3gq]
    
    but i got some errors.. if it's possible can u send me the library already done to put at construct or at last help me get this to work? i really apreciate.. thanks
    
    edit: I was running from the pythonw.exe so now i used cmd and i think it worked... made 2 folders...build and dist, at dist have library and dll..  i can now just make a folder named 'mysqldb' unzip them at python folder in construct?
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • build and dist, at dist have library and dll.. i can now just make a folder named 'mysqldb' unzip them at python folder in construct?

    Yes, that sounds about right...you could just unzip all of the .pyc files in the dist directory in your Python folder. If you follow the quickguide step for that everything should work.

    You could also put them all in a separate directory like you mentioned.

  • > build and dist, at dist have library and dll.. i can now just make a folder named 'mysqldb' unzip them at python folder in construct?

    >

    Yes, that sounds about right...you could just unzip all of the .pyc files in the dist directory in your Python folder. If you follow the quickguide step for that everything should work.

    You could also put them all in a separate directory like you mentioned.

    but do i need to substitute the filesi n the python directory in construct or i can just make a new folder and add all of em?

    cause i want to use podsixnet too but i don't know if by substituing the existing files ill cause any problem to other modules..

  • Either way works fine...I've done both. As long as your version of Python is 2.6..it isn't a problem to replace the current files with the ones you copy (but it is not necessary..just select "no" to overwriting existing files.

  • Either way works fine...I've done both. As long as your version of Python is 2.6..it isn't a problem to replace the current files with the ones you copy (but it is not necessary..just select "no" to overwriting existing files.

    thanks a lot for helping

    I will see if now I can access SQL databases

  • scidave

    hey dude, do u know why python can't get the info from EditBox.Text ?

    the '.Text' is appearing in red at the right bar.. is that okay? What means the red color?

    i'm trying this:

    import MySQLdb
    
    db = MySQLdb.connect("localhost","root","","TESTING" )
    
    cursor = db.cursor()
    
    sql = """INSERT INTO TEST(FIRST_NAME,
             LAST_NAME, AGE, SEX, INCOME)
             VALUES (EditBox.Text, EditBox2.Text, 20, 'M', 2000)"""
    
    try:
    
     cursor.execute(sql)
     db.commit()
    except:
     db.rollback()[/code:kxdkm6nk]
  • Now I've tryed add

    name = str(EditBox.Text) before sql instruction and change:

    sql = """INSERT INTO TEST(FIRST_NAME,
             LAST_NAME, AGE, SEX, INCOME)
             VALUES (EditBox.Text, EditBox2.Text, 20, 'M', 2000)"""[/code:1mua2ebh]
    
    to:
    [code:1mua2ebh]sql = """INSERT INTO TEST(FIRST_NAME,
             LAST_NAME, AGE, SEX, INCOME)
             VALUES (name, 'test', 20, 'M', 2000)"""[/code:1mua2ebh]
    
    but still nothing.. doesn't add nothing to the database, It's like the script can't read the text from editbox.. 
    If I change VALUES (name, 'test', 20, 'M', 2000) to VALUES ('nametest', 'test', 20, 'M', 2000) then it works.. but I need to make it add what is written in the editboxes..
  • Try this:

    sql = """INSERT INTO TEST(FIRST_NAME,
             LAST_NAME, AGE, SEX, INCOME)
             VALUES ('%s', '%s', 20, 'M', 2000)"""
    
    try:
    
    cursor.execute(sql,EditBox.Text,EditBox2.Text)
    db.commit()
    except:
    db.rollback()
    
    [/code:3c66z9fl]
    
    If that doesn't work you can try changing the cursor execute line to this (notice the commas):
    cursor.execute(sql,(EditBox.Text,),(EditBox2.Text,))
  • Try this:

    > 
    sql = """INSERT INTO TEST(FIRST_NAME,
             LAST_NAME, AGE, SEX, INCOME)
             VALUES ('%s', '%s', 20, 'M', 2000)"""
    
    try:
    
    cursor.execute(sql,EditBox.Text,EditBox2.Text)
    db.commit()
    except:
    db.rollback()
    
    [/code:30en8u9a]
    
    If that doesn't work you can try changing the cursor execute line to this (notice the commas):
    cursor.execute(sql,(EditBox.Text,),(EditBox2.Text,))
    

    I've tryed both ways with and without commas but none worked.. =(

    any more ideas?

  • Did you also try setting the EditBox.Text to python variables with the new way?

    name1 = EditBox.Text

    name2 = EditBox2.Text

    Then replace those names in the execute call.

    Then if that fails, try it without the single quotes around the %s....

    If none of those work, I'll download/install the library and see what's up.

  • Did you also try setting the EditBox.Text to python variables with the new way?

    name1 = EditBox.Text

    name2 = EditBox2.Text

    Then replace those names in the execute call.

    Then if that fails, try it without the single quotes around the %s....

    If none of those work, I'll download/install the library and see what's up.

    Ya I had already tryed those too and now tryed without the quotes around %s but don't worked too..

    If you could download them I would greatly appreciate your effort.. I'm getting crazy trying to make this work

  • Got it! I installed everything and experimented with the database and found this portion of the user guide helpful:

    http://mysql-python.sourceforge.net/MyS ... on-objects

    firstname = 'sci'
    lastname = 'dave'
    age = 20
    sex = "M"
    income = 2000
    
    sql = """INSERT INTO test(FIRST_NAME, LAST_NAME,
           AGE, SEX, INCOME) VALUES (%s, %s, %s, %s, %s)"""
    
    try:
    
        cursor.execute(sql , (firstname,lastname,age,sex,income))
        db.commit()
    except:
        db.rollback()
    
    [/code:2pt4equn]
    
    You could also hardcode values you want as well.  Also, notice that whether you are placing a string or int you always use a "%s" for them as the placeholder.
  • OMG Thank you!!!!! I'm gonna try this!

    Edit: Wowww it really worked! Can't thank you enough for this... I was getting crazy making this to work..

    once more, thanks!

    I'm trying to read from the DB with this script, not getting any error, just doesn't showing nothing:

    maxprice = 1000
    
    cursor.execute("""SELECT FIRST_NAME FROM TEST
              WHERE INCOME > %s""", (maxprice))
    
    results = cursor.fetchone()
    EditBox3.AppendText(results)[/code:yd0jhkoc]
    Do you know what might be the problem?
    
    EDIT2: Ok, I fixed I guess.. 
    changed EditBox3.AppendText(results) to EditBox3.AppendText(str(results))    
    I think this topic serves as a tutorial too.. xD
  • 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..

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)