Hello everyone.

I already know the C code required to use SQL statements within C++. Using mysql_real_connect, I was able to establish a connection to a remote MySQL server. The problem is, even though mysql_real_connect did not RETURN NULL, (meaning that a connection to the mysql server was established) I am unable to create databases, OR new tables using the MySQL handle obtained (via the mysql_real_connect function).

int errorcheck;
errorcheck = mysql_real_connect(conn, "myipaddress", "myusername", "mypassword", NULL, 0, NULL, 0);
if (errorcheck != NULL)
{MessageBox(hWnd, "Connection to server successful!", "Connection Status", MB_OK};

Questions:
-Is it possible for mysql_real_connect to not be null, but still be unsuccessful?
-What are the exact return values for: mysql_query, mysql_select_db, and mysql_real_connect?

Notes:
-I have already ensured that "remote" access to the mySQL database was permitted.
-I already know that mysql_real_connect returns NULL if a connection was not established to the MySQL server. However, I do not know if any other return values can be returned other than NULL or success.

Edited 6 Years Ago by PixelExchange: n/a

may be this bellow code snippet help you to print out what is the error goes on
actually.

MYSQL mysql;

mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
    fprintf(stderr, "Failed to connect to database: Error: %s\n",
          mysql_error(&mysql));
}

please note I caught that code from there.http://dev.mysql.com/doc/refman/5.0/en/mysql-real-connect.html where the MySql API documentation for C language interface.

Thank you for your reply. I've found the problem.. Rather simple really.. I was using the wrong mysql connector as the first arguement. I created two MYSQL variables. One was initiated, and the other was not. I used the one that was not initiated inside of my sql statements.

Also, I was aware of that site, as well as the code required to display the conflicting error.. but that was not sufficient information to figure out why I could not create any tables on a valid connection.

Edited 6 Years Ago by PixelExchange: n/a

This question has already been answered. Start a new discussion instead.