MySQL c++, problem z połączeniem do serwera.

0

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");
        
    }


0

Najpierw sprawdź czy standardowy client MySQL łączy się z tą bazą.

0

"Bazy danych nie są dostępne z zewnętrznych serwerów www, zatem nie możesz wrzucić strony na inny hosting i trzymać tylko bazy tutaj. "
czy to nie przypadkiem dlatego...?

0

A zna ktoś przykład takiego hostingu, darmowego i najlepiej polskiego i jak można to udostępnić?
zrobiłem sobie bazę danych na db4free.net ale tam to wszystko tak wooolno działa...

1 użytkowników online, w tym zalogowanych: 0, gości: 1