#pragma comment(lib, "libmysql.lib");
#include <my_global.h>
#include <mysql.h>
#include <windows.h>
#define SERVER "localhost" //works only with 127.0.0.1
#define USER "root"
#define PASSWORD ""
#define DATABASE "userx"
int main()
{
MYSQL *connect; // Create a pointer to the MySQL instance
connect=mysql_init(NULL); // Initialise the instance
if(!connect) /* If instance didn't initialize say so and exit with fault.*/
{
fprintf(stderr,"MySQL Initialization Failed");
return 1;
}
connect=mysql_real_connect(connect,SERVER,USER,PASSWORD,DATABASE,0,NULL,0);
if(connect){
printf("Connection Succeeded\n");
}
else{
printf("Connection Failed!\n");
}
return 0;
}
hey guys im trying to connect to a local database using the code above, it doesn't work thou when i use 'localhost', it works only when i used '127.0.0.1' instead of 'localhost'
so when i'm trying to connect now on my database online, it wont work ...my host name is something like hostname.xxxxx.com, so i tried to use the ip of my host which is 192.168.0.xxx but still doesn't work. I don't know what's wrong with this, im using ...MySQL Connector C 6.0.2