SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 08/10/2017, 05:30 PM   #1
Rufcio
Little Clucker
 
Join Date: Jul 2017
Posts: 5
Reputation: 0
Default Connect to second database

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
Rufcio is offline   Reply With Quote
Old 08/10/2017, 05:43 PM   #2
Maximun
Huge Clucker
 
Join Date: Jan 2014
Location: Localhost
Posts: 437
Reputation: 54
Default Re: Connect to second database

Sorry but we can't help you without any code, are you using 'local host' or under 'hosting' ?
Maximun is offline   Reply With Quote
Old 08/10/2017, 06:17 PM   #3
Rufcio
Little Clucker
 
Join Date: Jul 2017
Posts: 5
Reputation: 0
Default Re: Connect to second database

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:
Code:
#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;
}
Rufcio is offline   Reply With Quote
Old 08/10/2017, 06:24 PM   #4
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,133
Reputation: 445
Default Re: Connect to second database

There should be a file called "mysql_log.log" in the server directory. Post recent content here.
Abagail is offline   Reply With Quote
Old 08/10/2017, 06:44 PM   #5
Rufcio
Little Clucker
 
Join Date: Jul 2017
Posts: 5
Reputation: 0
Default Re: Connect to second database

mysql_log.txt **

I have something like that:
Code:
[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.
Rufcio is offline   Reply With Quote
Old 08/10/2017, 06:53 PM   #6
ConnorHunter
Big Clucker
 
Join Date: Jul 2013
Posts: 165
Reputation: 26
Default Re: Connect to second database

pawn Code:
#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.
ConnorHunter is offline   Reply With Quote
Old 08/10/2017, 07:07 PM   #7
Rufcio
Little Clucker
 
Join Date: Jul 2017
Posts: 5
Reputation: 0
Default Re: Connect to second database

ehh i'm not stupid ;p
on my pc i have it filled
Rufcio is offline   Reply With Quote
Old 08/10/2017, 07:10 PM   #8
Famalamalam
Huge Clucker
 
Famalamalam's Avatar
 
Join Date: Apr 2011
Posts: 469
Reputation: 50
Default Re: Connect to second database

Quote:
Originally Posted by Rufcio View Post
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?
Famalamalam is offline   Reply With Quote
Old 08/10/2017, 07:25 PM   #9
Jstylezzz
High-roller
 
Jstylezzz's Avatar
 
Join Date: Sep 2011
Location: Netherlands
Posts: 1,860
Reputation: 1572
Default Re: Connect to second database

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.
Jstylezzz is offline   Reply With Quote
Old 08/10/2017, 08:49 PM   #10
Rufcio
Little Clucker
 
Join Date: Jul 2017
Posts: 5
Reputation: 0
Default Re: Connect to second database

@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.
Rufcio is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql can't connect database [S-G]Cypher Scripting Help 1 03/10/2015 01:34 PM
mysql can't connect database [S-G]Cypher Scripting Help 0 03/10/2015 01:34 PM
MySQL database can't connect. [rG]Cold Server Support 0 28/09/2015 10:36 AM


All times are GMT. The time now is 04:10 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.