Open 2 MYSQL connections in 1 server
#1

I have created a script which will connect to a MYSQL server. It's the same server, however it's a different user and a different database name. My main script also uses MYSQL to save the accounts.
The problem is, if I run the filterscript which starts the second MYSQL connection, the MYSQL connection on the main script is confused with the MYSQL connection on the filterscript, so the MYSQL connection on the main script won't work.
My question is: Is it possible to open them both and work properly?
Reply
#2

It should be, however what are you saving in your other filterscript?
Reply
#3

I strongly suggest that you use different tables within 1 database.

OR

Close the current connection with
pawn Code:
mysql_close();
And reconnect to your new DB with
pawn Code:
new mysql = mysql_connect("127.0.0.1","root","mydatabase","mypass");
Reply
#4

Of course you can do it, just make two connections and write the connection handle in all your queries, saving results, freeing results etc. Look at the connection handles in https://sampwiki.blast.hk/wiki/MySQL
Reply
#5

Quote:
Originally Posted by [HiC]TheKiller
View Post
Of course you can do it, just make two connections and write the connection handle in all your queries, saving results, freeing results etc. Look at the connection handles in https://sampwiki.blast.hk/wiki/MySQL
How could I do that without using the parameters resultid and extraid (at query)
Reply
#6

First, connect to your two databases like this:

pawn Code:
new mysql1 = mysql_connect("127.0.0.1","root","mydatabase","mypass");
new mysql2 = mysql_connect("other ip","root2","mydatabase2","mypass2");
Then you can use the query function like this, depending on which connection you want to work with:

pawn Code:
mysql_query("SELECT * FROM `mytable` WHERE condition=true", mysql1); // This will be processed on connection 1
mysql_query("SELECT * FROM `mytable` WHERE condition=true", mysql2); // This will be processed on connection 2
Correct me if i'm wrong, it may be required to still use the threaded way of doing mysql, or specify the other extra variable(s). If so, then you will have to work with threaded callbacks.
Reply
#7

Since MYSQL_Query is defined like this:
pawn Code:
native mysql_query(query[],resultid = (-1),extraid = (-1),connectionHandle = 1);
I assume it will work on this way
pawn Code:
mysql_query("SELECT * FROM `mytable` WHERE condition=true", -1, -1, mysql1); // This will be processed on connection 1
mysql_query("SELECT * FROM `mytable` WHERE condition=true", -1, -1, mysql2); // This will be processed on connection 2
Someone please confirm this, or disconfirm this.
Reply
#8

You could indeed try that and test it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)