Is this thing possible ? I give rep++ (MYSQL)
#1

Is this thing possible?
I want to make 2 mysql connections in my gamemode , one with the samp-server database and one with the forum database.

like this:
pawn Код:
new static handlesamp;

new static handleforum;

#define mysql_host "127.0.0.1"
#define mysql_user "root"
#define mysql_password "password"
#define mysql_database "sa-mp"


#define mysql_host2 "127.0.0.1"
#define mysql_user2 "root"
#define mysql_password2 "passwordforum"
#mysql_database2 "forum"
Then connect each other.


Is this possible ? If i am wrong , how to do then?
Reply
#2

Quote:
Originally Posted by buburuzu19
Посмотреть сообщение
Is this thing possible?
I want to make 2 mysql connections in my gamemode , one with the samp-server database and one with the forum database.

like this:
pawn Код:
new static handlesamp;

new static handleforum;

#define mysql_host "127.0.0.1"
#define mysql_user "root"
#define mysql_password "password"
#define mysql_database "sa-mp"


#define mysql_host2 "127.0.0.1"
#define mysql_user2 "root"
#define mysql_password2 "passwordforum"
#mysql_database2 "forum"
Then connect each other.


Is this possible ? If i am wrong , how to do then?
well, actually i am not good at advanced MySQL but as far as i know yes, you can save your forum details using MySQL and the you can add it in your script.... like Project Reality has done!!

Sorry i am not able to help you out with it but i just made a confidence that you idea is not wrong, anyone senior will help you!
Reply
#3

yes, possible, but first, you have to create a variable for each one.
pawn Код:
new c1, c2; // creating connection handle for each one.
now after creating a variable for each one, we will connect to them when server starts, and define the variables:
pawn Код:
public OnGameModeInit()
{
     c1 = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password); // this is for server database
     c2 = mysql_connect(mysql_host2, mysql_user2, mysql_database2, mysql_password2); // this is for forum db.
     return 1;
}
however, in queries, you should determine the connection handle for each db, example:
pawn Код:
public OnPlayerConnect(playerid)
{
   new name[32]; // an example
   GetPlayerName(playerid, name, sizeof name); // an example
   mysql_tquery(c1, "SELECT `Password` FROM `players` WHERE `name`='%s' LIMIT 1", "CheckPlayer", "i", playerid);
   return 1;
}
as you see in mysql_tquery function, first parameter (the connection handle was c1) be cause we want to execute the query in the "players" database which we defined, we would use c2 for the forum db query.
Reply
#4

What I would advise you to do is to pass the connection handle to the callback via mysql_tquery. This way you don't really have to bother with globals. e.g.:
PHP код:
mysql_tquery(forumdbquery"MyCallback""dd"playeridforumdb);

// ...

public MyCallback(playeridconnectionHandle)
{
    new 
rows cache_get_row_count(connectionHandle);
    
// ...

Reply
#5

Quote:
Originally Posted by Sawalha
Посмотреть сообщение
yes, possible, but first, you have to create a variable for each one.
pawn Код:
new c1, c2; // creating connection handle for each one.
now after creating a variable for each one, we will connect to them when server starts, and define the variables:
pawn Код:
public OnGameModeInit()
{
     c1 = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password); // this is for server database
     c2 = mysql_connect(mysql_host2, mysql_user2, mysql_database2, mysql_password2); // this is for forum db.
     return 1;
}
however, in queries, you should determine the connection handle for each db, example:
pawn Код:
public OnPlayerConnect(playerid)
{
   new name[32]; // an example
   GetPlayerName(playerid, name, sizeof name); // an example
   mysql_tquery(c1, "SELECT `Password` FROM `players` WHERE `name`='%s' LIMIT 1", "CheckPlayer", "i", playerid);
   return 1;
}
as you see in mysql_tquery function, first parameter (the connection handle was c1) be cause we want to execute the query in the "players" database which we defined, we would use c2 for the forum db query.
rep+1 thanks.
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
What I would advise you to do is to pass the connection handle to the callback via mysql_tquery. This way you don't really have to bother with globals. e.g.:
PHP код:
mysql_tquery(forumdbquery"MyCallback""dd"playeridforumdb);
// ...
public MyCallback(playeridconnectionHandle)
{
    new 
rows cache_get_row_count(connectionHandle);
    
// ...

i will rep you tommorrow because i reached the limit , thanks too.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)