Witam mam taki problem otóż robię program który zapisuje i pobiera dane z bazy danych MySQL, problem mam z tym że ciągle mi wywala błąd połączenia z serwerem, hosting mam na CBA.pl, przez phpMyAdmin loguję się bez problemu.
Fragment kodu:
#include <windows.h>
#include <MySQL\mysql.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
// Database name...
char g_szHost[] = "mysql.cba.pl";
UINT g_unPort = MYSQL_PORT;
char g_szUserName[] = "User";
char g_szPassword[] = "Haslo";
char g_szDatabase[] = "Baza";
char g_szSQLStatement[] = "SELECT * test";
// Entry point...
int main(int nArguments, char *pszArguments[])
{
// Variables...
MYSQL *myDatabase = NULL;
MYSQL_RES *myResult = NULL;
MYSQL_FIELD *myField = NULL;
MYSQL_ROW myRow = NULL;
UINT unRecords = 0;
UINT unFields = 0;
UINT unIndex = 0;
UINT unFieldIndex = 0;
// Initialize MySQL...
myDatabase = mysql_init(NULL);
// Failed...
if(!myDatabase)
{
// Alert user...
printf("] Error: Unable to initialize MySQL API...\n");
// Cleanup, abort, terminate...
mysql_close(myDatabase);
getch();
return 0;
}
// Connect to server and check for error...
if(!mysql_real_connect(myDatabase, g_szHost, g_szUserName, g_szPassword,
NULL, g_unPort, NULL, 0))
{
// Alert user...
printf("] Error: Unable to connect to server...\n");
}
// Select database in server and check for error...
if(mysql_select_db(myDatabase, g_szDatabase) < 0)
{
// Alert user...
printf("] Error: Unable to select database...\n");
}