Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with arrays please. #5

Open
kizeren opened this issue Aug 10, 2016 · 3 comments
Open

Help with arrays please. #5

kizeren opened this issue Aug 10, 2016 · 3 comments

Comments

@kizeren
Copy link

kizeren commented Aug 10, 2016

It wasn't to hard to figure out how to do arrays in php which is the language I am use to. Godot has been pretty fun to use then I found your pluging. It is implemented and I figured out pretty easily how to create a table and insert information into said table. But for the life of me, I can not figure how in godot or gdsqlite how to retrieve items like I do in php from the array. Here is the piece of code I am messing with to try and figure this out.

`func _on_loginbutton_pressed():
if (db.open("user://data.sql") != db.SQLITE_OK):
print("ERR: ", db.get_errormsg())
return
sql = db.fetch_array("SELECT * FROM players WHERE name ='"+str(Globals.get("Playername"))+"';")

if (sql != array):
    sql = db.fetch_array("SELECT pass FROM players WHERE name ='"+str(Globals.get("Playername"))+"';")
    if (sql == Globals.get("pass")):
        print("Match!")`

Any help would be much appreciated.

@khairul169
Copy link
Owner

khairul169 commented Aug 12, 2016

Do you want to check for username & password?
Why not do this?

var rows = db.fetch_array("SELECT name, pass FROM players WHERE name='"+str(Globals.get("Playername"))+"' AND pass='"+str(Globals.get("pass"))+"' LIMIT 1;");
if rows.empty():
print("Username and pass is not found");
else:
print("Username & password is match! Your username is ", rows['name']);

You can also use sql.count() to get fetched rows count.. the same as mysql_num_rows from php..

@kizeren
Copy link
Author

kizeren commented Aug 12, 2016

The sql['name'] I knew from php to do column names you had to call the
associate row etc .... but with this fetch_array already does all the
conversion for you?

On Fri, Aug 12, 2016 at 4:52 AM, Khairul notifications@github.com wrote:

Do you want to check for username & password?
Why not do this?

sql = db.fetch_array("SELECT name, pass FROM players WHERE name ='"+str(Globals.get("Playername"))+"' AND pass='"+Globals.get("pass")+"' LIMIT 1;");
if sql.empty():
print("Username and pass is not found");
else:
print("Username & password is match! Your username is ", sql['name']);


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#5 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACW6VqiN05v-Bw45jum-GALvdO_Y_SSRks5qfEJ0gaJpZM4JgyAP
.

@khairul169
Copy link
Owner

khairul169 commented Aug 13, 2016

Yes it does..

$query = mysql_query("SELECT * FROM players");
while ($i = mysql_fetch_array($query, MYSQL_BOTH)) {
    echo "ID: " . $i[0];
    echo "Name: " . $i['name'];
}

Can be done in gdscript with:

var query = "SELECT * FROM players";
for i in db.fetch_array(query):
    print ("ID: ", i[0]);
    print ("Name", i['name']);

What is returned by db.fetch_array is an array of rows..
For the conversion case, i don't know what that mean.. but for the detection of data type is already implemented here..

CMIIW 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants