Using MySQL C API

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

Using MySQL C API

Postby TRU3 » 07. September 2010 17:23

I am having trouble accessing my MySQL database in a Visual Studio Visual C++ project. I setup the include and lib directories with no problem. It compiles, links to libmysql.lib, and runs, however, I get this error when trying to connect to MySQL with mysql_real_connect():
Error 2003: Can't connect to MySQL Server on 'localhost' (10061)


I'm not sure what the issue is because I'm using Xampp to host my website projects. I was able to create and access a MySQL database in PHP...

Here is what my initialization code looks like:
Code: Select all
// global declarations
MYSQL *mysql = NULL;

...


// initialize MySQL and connect to a database
mysql = mysql_init(NULL);
if(!mysql)
{
   sprintf(text, "Error %u: %s\n", mysql_errno(mysql), mysql_error(mysql));
   MessageBox(NULL, text, "Fatal Error", NULL);
   return false;
}

// attempt to connect to the trial
if(!mysql_real_connect(mysql, "localhost", "root", "", NULL, 3306, NULL, 0))
{
   sprintf(text, "Error %u: %s\n", mysql_errno(mysql), mysql_error(mysql));
   MessageBox(NULL, text, "Fatal Error", NULL);
   return false;
}


As you can see, I am using port 3306 to access MySQL. Is this what Xampp uses? I did some research, and it looks right.
TRU3
 
Posts: 1
Joined: 07. September 2010 17:14

Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 17 guests