Problem with MySQL connector/c 6.0.2 with MySQL 5.1.49-1ubuntu8
Posted by: Say Tan
Date: January 11, 2011 12:54AM

Hi, I have managed to compile a very elementary C program communicating with MySQL Server 5.1.49. But it is getting stuck at mysql_real_connect()

Code as follows:

------------- Code starts here! ----------------------

/* client1.c - connect to and disconnect from MySQL server */
#include <my_global.h>
#include <mysql.h>

static char *opt_host_name = "localhost"; /* server host (default=localhost) */
static char *opt_user_name = "admin"; /* username (default=login name) */
static char *opt_password = "password"; /* password (default=none) */
static unsigned int opt_port_num = 0; /* port number (use built-in value) */
static char *opt_socket_name = NULL; /* socket name (use built-in value) */
static char *opt_db_name = NULL; /* database name (default=none) */
static unsigned int opt_flags = 0; /* connection flags (none) */

static MYSQL *conn; /* pointer to connection handler */

int main (int argc, char *argv[]) {

/* initialize connection handler */
conn = mysql_init (NULL);

if (conn == NULL) {
printf("unable to create conn\n");
exit(1);
}
else {
printf("created conn\n");
}
/* connect to server */
if (!mysql_real_connect (conn, opt_host_name, opt_user_name, opt_password,
opt_db_name, opt_port_num, opt_socket_name, opt_flags)) {
printf("unable to connect to server\n");
exit(1);
}
/* disconnect from server */
mysql_close (conn);
exit (0);
}

------------- Code ends here! ---------------------

Server information as follows:
MySQL Version: MySQL 5.1.49-1ubuntu8
Network Name: localhost.localdomain
IP: 127.0.0.1

I connected successfully to the MySQL server using MySQL Administrator (MySQL Client Version 5.1.49)

ps - code was lifted from the Internet.

Options: ReplyQuote


Subject
Views
Written By
Posted
Problem with MySQL connector/c 6.0.2 with MySQL 5.1.49-1ubuntu8
2892
January 11, 2011 12:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.