brian writes:
> Friends,
>
> I run RedHat Linux 5.1. I have installed MySQL Server, Client and Devel
> on the same machine.
>
> The following C++ code
>
> #include <./mysql/mysql.h>
> #include <stdio.h>
> #include <iostream.h>
>
> MYSQL a_mysql;
>
> void main(void)
> {
> if(!mysql_real_connect(&a_mysql, "localhost", "user", "password",
> "test", 0, 0, 0))
> {
> cout << mysql_error(&a_mysql) << endl << endl;
> exit(0);
> }
>
> cout << "Everything went OK!!!" << endl << endl;
>
>
> }
>
> with the following compile
>
> g++ sqltest.cpp /usr/lib/mysql/libmysqlclient.a -osqltest
>
> (the suggested "g++ -I/path_to_mysql/include/mysql
> -L/path_to_mysql/lib/mysql myprogram.c -lmysqlclient" gives a message
> that it cannot find mysqlclient)
>
> will run and give the following error message:
>
> Can't connect to MySQL server on localhost (111)
>
> I have also tried "" for the hostname as well as 127.0.0.1 and the
> machines alias all with the same result.
>
> I can log into mysql from the command line with:
>
> mysql -u root -p
>
> and mess around just fine.
>
> Any advice would be appreciated.
>
> Thanks,
> Brian
>
Hi!
First of all, you have not called mysql_init function.
Second, you have set in real_connect a port to 0, instead to 3306 or
similar, although it is a lesser mistake.
Third, if you do not want to use all these options, why don't you just
call mysql_connect.
And in order to simplify matters further, why don't you use C++ API,
found at:
http://metalab.unc.edu/kevina/mysql++
Sinisa
+---------------------------------------------------------------------+
| TcX ____ __ _____ _____ ___ == mysql@stripped |
| /*/\*\/\*\ /*/ \*\ /*/ \*\ |*| Sinisa Milivojevic |
| /*/ /*/ /*/ \*\_ |*| |*||*| mailto:sinisa@stripped |
| /*/ /*/ /*/\*\/*/ \*\|*| |*||*| Belgrade |
| /*/ /*/ /*/\*\_/*/ \*\_/*/ |*|_____ Serbia |
| ^^^^^^^^^^^^/*/^^^^^^^^^^^\*\^^^^^^^^^^^ |
| /*/ \*\ Developers Team |
+---------------------------------------------------------------------+
Thread |
---|
• C API | brian | 13 Mar |
• C API | sinisa | 14 Mar |