MySQL Connect from Outside Computer
Here is 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_SHOWCOUNT, LB_ADDSTRING, 0, (LPARAM)TEXT("Attempting to Connect to Database...."));
//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", "username","password","database",0,NULL,0);
SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Attempting To Connect To Database....");
mysql_query(pConnection,"SELECT * FROM products order by itemN"); //query the database
pResult = mysql_store_result(pConnection);
TCHAR szBuffer[50];
wsprintf (szBuffer, TEXT ("%d"), mysql_num_rows (pResult));
SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Connected....Please Wait!");
while ((Row = mysql_fetch_row(pResult)))
{
TCHAR szProducts[100];
wsprintf(szProducts, "%s.....%s.....%s.....%s....%s", Row[1], Row[4], Row[5], Row[7], Row[9]);
SendDlgItemMessage (hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)szProducts);
}
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("______________________"));
SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Done");
mysql_free_result(pResult);
break;
Here's what I'm trying to do:
I have a MySQL database that resides on one computer and I want to connect to it from another workstation using TCP but I don't have MyODBC setup because I'm not sure if that's what I need and I don't know what all I have to have in order to do it or where to start.
If it's as simple as specifying a port number please show me how.
Here was my only guess:
mysql_real_connect(pConnection, "http://192.168.0.2:3306", "username","password","database",0,NULL,0);
But that didn't work.
Thanks for the help ahead of time