Thread: mysql_real_connect and c++

  1. #1
    Registered User juschillin's Avatar
    Join Date
    Sep 2002
    Posts
    20

    mysql_real_connect and c++

    here's my code:

    Code:
    case IDC_GET:
    					MYSQL *pConnection; 
    					MYSQL_RES *pResult;   //pointer to the result set structure
    					MYSQL_ROW Row;
    					pConnection = mysql_init(NULL);
    					SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Attempting to Connect to"));
    					SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Database......."));
    					mysql_real_connect(pConnection, "localhost", "alakazam","username","password",0,NULL,0);
        				SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Connected!"));
    					mysql_query(pConnection,"SELECT * FROM products"); //query the database
    					pResult = mysql_store_result(pConnection); 
    					TCHAR szBuffer[50];
    					wsprintf (szBuffer, TEXT ("%d"), mysql_num_rows (pResult));
    					SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Total # of Products In Database:"));
    					SendDlgItemMessage (hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)szBuffer);
    
    					//printf("\n\nThe Number Of products in the database: %d\n\n",mysql_num_rows(pResult));
    					SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("______________________"));
    					mysql_free_result(pResult);
    				break;




    I got everything working, except.....I want to run this program on other computers and use the mysql database running on this computer. How do I replace the "localhost" in the mysql_real_connect with the ip address of the computer i need to connect to?

    I have tried with "192.168.0.2" and "http://192.168.0.2" and nothing seems to work.

    can anybody help me. I basically need to connect to "x" mysql database from computer "y".
    !Carpe Diem!
    "Sieze the Day"

  2. #2
    Registered User juschillin's Avatar
    Join Date
    Sep 2002
    Posts
    20
    Does anybody know the answer to this one???
    !Carpe Diem!
    "Sieze the Day"

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    13
    you need the IP of the other computer that the MySQL server is running on, the correct port number, too.

    And the computer has to be accesible from your location.

    Just like anything else on the internet or a network.

Popular pages Recent additions subscribe to a feed