SA-MP Forums Archive
Connect to second database - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Connect to second database (/showthread.php?tid=642873)



Connect to second database - Rufcio - 08.10.2017

Hello,
At first apologize for my english, i'm from Poland.

I have a problem, I can't connect with second database which is on other server.
Is there any solution to this?

Regards


Re: Connect to second database - Maximun - 08.10.2017

Sorry but we can't help you without any code, are you using 'local host' or under 'hosting' ?


Re: Connect to second database - Rufcio - 08.10.2017

I have GameMode with MySQL systems, i created new filterscript, which has a task to do - sending messages to shoutbox table on other server. Code fs:
Код:
#include <samp/a_samp>
#include <plugin/a_mysql>
#include <plugin/sscanf2>
#include <PTS/engine/izcmd>
#include <PTS/security/Cenzura>
#include <kolory>
#include <SAM/DataConvert>
#define MYSQL_HOST "ip...."
#define MYSQL_USER "user"
#define MYSQL_PASS "xxxx"
#define MYSQL_DB   "mybb"
new ConMySQL2;

public OnFilterScriptInit()
{
	new rConn2 = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_DB,MYSQL_PASS);
	if(!rConn2 || !mysql_ping(rConn2)){
		printf(" Nie udalo sie polaczyc z baza danych2");
		SendClientMessageToAll(COLOR_ORANGE,"Nie działa");
		SendRconCommand("exit");
		return 0;
	}
	print("Zaladowano");
	SendClientMessageToAll(COLOR_ORANGE,"Działa");
	
	ConMySQL2 = rConn2;
    return 1;
}
public OnFilterScriptExit()
{

	mysql_close(ConMySQL2);
    return 1;
}



stock GetPlayerNick(playerid){
	new pnick[MAX_PLAYER_NAME];
	GetPlayerName(playerid,pnick,sizeof(pnick));
	return pnick;
}


CMD:shoutbox(playerid, params[])
{
	new text[200];
	new query[500];
	new string[500];
	if(IsPlayerAdmin(playerid))
	{
		if(sscanf(params,"s[256]",text))
		{
			return SendClientMessage(playerid,COLOR_WHITE,"Wpisz: /shoutbox [Tekst]");
		}
		else
		{
			format(query, sizeof(query), "INSERT INTO `mybb_dvz_shoutbox` (`uid`, `text`) VALUES ('0', '%s: %s');", GetPlayerNick(playerid), text); 
			mysql_query(query, ConMySQL2);
			format(string,sizeof(string),"Dodałeś wiadomość na shoutboxa: {FF0000}%s",text);
			SendClientMessage(playerid, COLOR_RED, string);
		}
	}
	else
	{
	SendClientMessage(playerid,COLOR_RED,"Nie jesteś godzien tej komendy");
	}
	return 1;
}



Re: Connect to second database - Abagail - 08.10.2017

There should be a file called "mysql_log.log" in the server directory. Post recent content here.


Re: Connect to second database - Rufcio - 08.10.2017

mysql_log.txt **

I have something like that:
Код:
[18:35:11] ---------------------------
[18:35:11] MySQL Debugging activated (10/08/17)
[18:35:11] ---------------------------
[18:35:11]  
[18:35:16] >> mysql_query( Connection handle: 1 )
[18:35:16] CMySQLHandler::Query(resultID) - Threaded query with id 2 started. (Extra ID: -1)
[18:35:16] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()
[18:35:16] OnQueryError() - Called.
[18:35:21] >> mysql_close( Connection handle: 2 )
[18:35:21] CMySQLHandler::~CMySQLHandler() - deconstructor called.



Re: Connect to second database - ConnorHunter - 08.10.2017

pawn Код:
#define MYSQL_HOST "ip...."
#define MYSQL_USER "user"
#define MYSQL_PASS "xxxx"
#define MYSQL_DB   "mybb"
You need to fill in your database settings here then re-compile.


Re: Connect to second database - Rufcio - 08.10.2017

ehh i'm not stupid ;p
on my pc i have it filled


Re: Connect to second database - Famalamalam - 08.10.2017

Quote:
Originally Posted by Rufcio
Посмотреть сообщение
ehh i'm not stupid ;p
on my pc i have it filled
Lol. I don't see why you can't just create another connection when you're booting up if you want to connect to another database?


Re: Connect to second database - Jstylezzz - 08.10.2017

It might be worth mentioning that some systems that run MySQL servers block remote connections. In order to connect to those databases, you need to whitelist your IP on the DB host system. When I was using cPanel, remote connections got blocked.
By seeing this log, I'm not certain whether it's an issue of the connection failing, or an error being thrown from a query you're performing.


Re: Connect to second database - Rufcio - 08.10.2017

@Famalamalam Could u make it more clear,please?
@Jstylezzz in phpmyadmin i enabled login from every ip, in mysql config on ubuntu i have commented bind-address. If i using only 1 connection (with second mysql server) all working, but if im trying connect to 2databases in this same time i have that error.