Mysql Implementation
Mysql Implementation
Hey again,
im doing some testing on the game and i need to communicate with a local mysql database. How can i do it? I mean download and setup mysql locally.
im doing some testing on the game and i need to communicate with a local mysql database. How can i do it? I mean download and setup mysql locally.
Re: Mysql Implementation
Installing MySQL is out of the scope of our support, but you can find all the directions from the mysql website.
In order to communicate with the database via SmartFoxServer read the documentation here:
http://docs2x.smartfoxserver.com/Gettin ... wtos#item2
Then you can take a look at these "recipes":
http://docs2x.smartfoxserver.com/Develo ... se-recipes
And this too:
http://docs2x.smartfoxserver.com/Develo ... -assistant
cheers
In order to communicate with the database via SmartFoxServer read the documentation here:
http://docs2x.smartfoxserver.com/Gettin ... wtos#item2
Then you can take a look at these "recipes":
http://docs2x.smartfoxserver.com/Develo ... se-recipes
And this too:
http://docs2x.smartfoxserver.com/Develo ... -assistant
cheers
Re: Mysql Implementation
Thank you, i will check it
Re: Mysql Implementation
Ok, some problems here,
i used the MySQL JDBC Driver but i dont know where to drop the file. SFS2X\extensions\__lib__ or SFS2X\lib?
how can i find the database driver class and the connection string (what port)?
i used the MySQL JDBC Driver but i dont know where to drop the file. SFS2X\extensions\__lib__ or SFS2X\lib?
how can i find the database driver class and the connection string (what port)?
Re: Mysql Implementation
SFS2X\lib
driver class = org.gjt.mm.mysql.Driver
connection string = jdbc:mysql://host/dbname
* change host and dbname to the actual host and database name
More info: here
driver class = org.gjt.mm.mysql.Driver
connection string = jdbc:mysql://host/dbname
* change host and dbname to the actual host and database name
More info: here
Re: Mysql Implementation
Thank you, i installed wampserver for the mysql and it uses 127.0.0.1 (cauz localhost is for sfs) and i put jdbc:mysql://127.0.0.2:3306/mydb but it says cant access "root@localhost". So it seems it still tries to connect to 127.0.0.1 instead of .2
I also want to send a query via c# script so i use
IDBManager connection = dbManager.getConnection();
but the system doesn't recognize the IDBManager class. Do i have to import a certain sfs class?
I also want to send a query via c# script so i use
IDBManager connection = dbManager.getConnection();
but the system doesn't recognize the IDBManager class. Do i have to import a certain sfs class?
Re: Mysql Implementation
Queries cannot be executed from client side, only from server side.
You will have to send a request from the client to your server side Extension, which in turn will talk to your database.
If you're new to these concepts take it one step at a time from the documentation, from the Development Basics section.
http://docs2x.smartfoxserver.com/
You will have to send a request from the client to your server side Extension, which in turn will talk to your database.
If you're new to these concepts take it one step at a time from the documentation, from the Development Basics section.
http://docs2x.smartfoxserver.com/
Re: Mysql Implementation
Thank you again, and what of the other problem?
Re: Mysql Implementation
I don't understand the other problem.
no localhost is another way of saying 127.0.0.1, they are the same thing actually, only the first is a domain name and the second is the actual IP address where the domain resolves to.
If the database runs on 127.0.0.1 you should use 127.0.0.1, not .2
i installed wampserver for the mysql and it uses 127.0.0.1 (cauz localhost is for sfs)
no localhost is another way of saying 127.0.0.1, they are the same thing actually, only the first is a domain name and the second is the actual IP address where the domain resolves to.
and i put jdbc:mysql://127.0.0.2:3306/mydb but it says cant access "root@localhost". So it seems it still tries to connect to 127.0.0.1 instead of .2
If the database runs on 127.0.0.1 you should use 127.0.0.1, not .2
Re: Mysql Implementation
No, database runs on .2 but no matter what ip i use on admin tool, i get 'root@localhost'. Another question though. I created an extension with 2 classes:
I get those two:
Code: Select all
package mysql;
import com.smartfoxserver.v2.extensions.SFSExtension;
public class Main extends SFSExtension {
public void init() {
addRequestHandler("PickUp", PickUp.class);
}
}
Code: Select all
package mysql;
import java.sql.SQLException;
import com.smartfoxserver.v2.db.IDBManager;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
public class PickUp extends BaseClientRequestHandler{
public void handleClientRequest(User sender, ISFSObject params){
IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
String sql = "myquery";
try {
dbManager.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I get those two:
Re: Mysql Implementation
In both your screenshots it's not possible to read the error message, it is truncated.
Can you please copy it and paste it here?
Also I'd like to see the settings of you DBManager in the AdminTool
thanks
Can you please copy it and paste it here?
Also I'd like to see the settings of you DBManager in the AdminTool
thanks
Re: Mysql Implementation
Hello sorry for late to answer. I fixed the problem, but i need help with custom login.
I followed this script:
http://docs2x.smartfoxserver.com/Gettin ... wtos#item3
but it only says what happens in case of wrong credentials. If they are correct what happpens?
I followed this script:
http://docs2x.smartfoxserver.com/Gettin ... wtos#item3
but it only says what happens in case of wrong credentials. If they are correct what happpens?
Re: Mysql Implementation
Hello,
If the credentials are correct, then no exception is thrown and some events are fired: SFSEvent.LOGIN on the client and SFSEventType.USER_JOIN_ZONE on the server-side. After an User is successfully logged in, it can interact with the server: send custom extension requests, join a room, chat with buddies, chat with other users, play games, etc.
For more information about how the server architecture works, I suggest you to read the [url)http://docs2x.smartfoxserver.com/DevelopmentBasics/introduction]Development Basics[/url] section of the official documentation.
Cheers
If the credentials are correct, then no exception is thrown and some events are fired: SFSEvent.LOGIN on the client and SFSEventType.USER_JOIN_ZONE on the server-side. After an User is successfully logged in, it can interact with the server: send custom extension requests, join a room, chat with buddies, chat with other users, play games, etc.
For more information about how the server architecture works, I suggest you to read the [url)http://docs2x.smartfoxserver.com/DevelopmentBasics/introduction]Development Basics[/url] section of the official documentation.
Cheers
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Re: Mysql Implementation
Hey, thank you, i did it with a fake-custom login. But i have another question
When someone registers the extension checks if the username or the mail he entered already exist. So it uses this code:
My question is what do the arrays contain of they don't find a match. If they find one the access index is 0 right?
When someone registers the extension checks if the username or the mail he entered already exist. So it uses this code:
Code: Select all
ISFSArray check = dbManager.executeQuery("SELECT * FROM player WHERE username = ?", new Object[] {params.getUtfString("Username")});
ISFSArray check2 = dbManager.executeQuery("SELECT * FROM player WHERE email = ?", new Object[] {params.getUtfString("E-Mail")});
//for(int i = 0; i <= check.size()-1; i++){
ISFSObject Credential = check.getSFSObject(0);
ISFSObject Credential2 = check2.getSFSObject(0);
//do something
}
My question is what do the arrays contain of they don't find a match. If they find one the access index is 0 right?
Re: Mysql Implementation
Just a little side note. We provide a specific class called LoginAssistant which makes this much more easy, have you taken a look here?
http://docs2x.smartfoxserver.com/Develo ... -assistant
In your code you're running 2 queries when you actually need just one,
The array contains as many rows of data as your query produced. If your query didn't find anything the size of the array will be zero.
http://docs2x.smartfoxserver.com/Develo ... -assistant
In your code you're running 2 queries when you actually need just one,
Code: Select all
"SELECT * FROM player WHERE username = ? AND email = ?"
My question is what do the arrays contain of they don't find a match. If they find one the access index is 0 right?
The array contains as many rows of data as your query produced. If your query didn't find anything the size of the array will be zero.
Code: Select all
if (returnArray.size() > 0)
{
// Ok, the query did return data
}
Who is online
Users browsing this forum: No registered users and 133 guests