[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-plusplus
Subject:    Re: why donn't work mysql_real_connect
From:       "Arlis Rose" <arlis () endevouraerospace ! com>
Date:       2005-06-30 18:21:08
Message-ID: da1coq$pda$1 () sea ! gmane ! org
[Download RAW message or body]

See code at bottom:

"mm" <mt1900@rdslink.ro> wrote in message 
news:42BC1A51.8080607@rdslink.ro...
> Dear friends,
> This is my first cpp module working with mySQL.
> It looks like the error is located in
> MYSQL *m=mysql_real_connect(myDB, host, user, passwd, ...
> There is a way to find out step by step which parameters is wrong?
> I am working with Fedora core 3
> and MySQL 3.23.58
> Thanks,
> MT
>
> ++++++++++++++++++ CPP module +++++++++++++++++++++++++++++++++++++++
> #include "/usr/include/mysql/mysql.h"
>
>
> int modulMySQL() {
> printf("modulMySQL 01\n"); fflush(stdout);
> // MYSQL *mysql_init(MYSQL *mysql)
> // ===========================================
> MYSQL *myDB;
> MYSQL *mysql_init(myDB);
> printf("modulMySQL 02\n"); fflush(stdout);
>
>
> // MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char
> //  *user, const char *passwd, const char *db, unsigned int port,
> //  const char *unix_socket, unsigned long client_flag)
> // ====================================================================
> char *host=NULL, user[]="myname", passwd[]="mypass";
> char db[]="ro";
>
>
> unsigned int port=3306;
> const char *unix_socket=NULL;
> unsigned long client_flag=0;
> MYSQL *m=mysql_real_connect(myDB, host, user, passwd,
> db, port, unix_socket, client_flag);
>
> printf("modulMySQL 03\n"); fflush(stdout);
>
> // int mysql_ping(MYSQL *mysql)
> // ===================================
> int p=mysql_ping(myDB);
> printf("Return Values - Zero if the server is alive.p=[%i]\n", p);
>
> }
>
> +++++++++++++++++++++ Compilation & Execution +++++++++++++++++++
> CFG=/usr/lib/mysql/mysql_config
> sh -c "gcc -o myC `$CFG --cflags` -lstdc++ 01.cpp `$CFG --libs`"
> ./myC > 01_out.txt
>
> ++++++++++++++++++++++++++  01_out.txt  ++++++++++++++++++++++++++
> modulMySQL 01
> modulMySQL 02

Hey, hopefully this will help you out, just cut and pasted some old code I 
had for determining which connection parameter is messing up.
MYSQL * connEmail = mysql_init(NULL); //Fleming server is 142.237.42.101

if (!mysql_real_connect(connEmail, myIP, aVAR, bVAR, cVAR, 3306, NULL, 0)) {

//AfxMessageBox("There was an error connecting to the database");

//if (mysql_errno(connEmail)== CR_CONN_HOST_ERROR)

// AfxMessageBox("Failed to connect to the MySQL server.");

//else if (mysql_errno(connEmail)== CR_CONNECTION_ERROR)

// AfxMessageBox("Failed to connect to the local MySQL server.");

//else if (mysql_errno(connEmail)== CR_IPSOCK_ERROR)

// AfxMessageBox("Failed to create an IP socket.");

//else if (mysql_errno(connEmail)== CR_OUT_OF_MEMORY)

// AfxMessageBox("Out of memory.");

//else if (mysql_errno(connEmail)== CR_SOCKET_CREATE_ERROR)

// AfxMessageBox(" Failed to create a Unix socket.");

//else if (mysql_errno(connEmail)== CR_UNKNOWN_HOST)

// AfxMessageBox("Failed to find the IP address for the hostname.");

//else if (mysql_errno(connEmail)== CR_VERSION_ERROR)

// AfxMessageBox("A protocol mismatch resulted from attempting to connect to 
a server with a client library that uses a different protocol version. This 
can happen if you use a very old client library to connect to a new server 
that wasn't started with the --old-protocol option.");

//else if (mysql_errno(connEmail)== CR_NAMEDPIPEOPEN_ERROR)

// AfxMessageBox("Failed to create a named pipe on Windows.");

//else if (mysql_errno(connEmail)== CR_NAMEDPIPEWAIT_ERROR)

// AfxMessageBox(" Failed to wait for a named pipe on Windows.");

//else if (mysql_errno(connEmail)== CR_NAMEDPIPESETSTATE_ERROR)

// AfxMessageBox("Failed to get a pipe handler on Windows.");

//else if (mysql_errno(connEmail)== CR_SERVER_LOST)

// AfxMessageBox("If connect_timeout > 0 and it took longer than 
connect_timeout seconds to connect to the server or if the server died while 
executing the init-command.");

mysql_close(connEmail);



BTW - if you are going to leave this debugging section in the code be 
smarter than me and create an int equal to mysql_errno(connEmail); and check 
that instead of calling the function a million times :)




-- 
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:    http://lists.mysql.com/plusplus?unsub=mysql-plusplus@progressive-comp.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic