Hi,
I did it so I thank you again. Belove is my code that did it, I hope, what I expect. I notice the version of documentation not the same as my copy on my hard drive.
Thanks again,
mt

#include "/usr/include/mysql/mysql.h"
int modulMySQL() {
MYSQL mysql;
printf("01\n"); fflush(stdout);
mysql_init(&mysql);


printf("02 \n"); fflush(stdout);
if (!mysql_real_connect(&mysql, NULL,"user","pass","ro",0,NULL,0))
{
   fprintf(stderr, "Failed to connect to database: Error: %s\n",
         mysql_error(&mysql));
}
printf("OK\n"); fflush(stdout);
}



Mathias wrote:

Hi,
I don't use C APPI, but found this in docs for you :
*********** connect sample :
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));
}
********************

They give port, unix_socket, client_flag the values 0,NULL,0. Try this.

All the rest is at http://dev.mysql.com/doc/mysql/en/mysql-real-connect.html
and http://dev.mysql.com/doc/mysql/en/c-api-functions.html

Mathias
Selon mm <[EMAIL PROTECTED]>:

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




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]





Hope that helps
:o)
Mathias



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to