LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Mysql connection problem (https://www.linuxquestions.org/questions/linux-newbie-8/mysql-connection-problem-830437/)

renzorizzato 09-05-2010 06:11 AM

Mysql connection problem
 
I'm tryng to write a simple program c++ to connect to Mysql database based in my 127.0.0.1 server:

int main (void) {
cout << "\033[2J" << "\033[0;0f";

MYSQL mysql;
MYSQL *conn;

conn = mysql_init(&mysql);
cout << "conn = " << conn << "\n";
// cout << "mysql = " << &mysql;
int mysql_ping(MYSQL *mysql);

if (!mysql_real_connect(conn, host, db_user, db_pass, database, 0, NULL, 0))
{
fprintf(stderr, "Errore di connessione al database: Error: %s\n", mysql_error(conn));
}

cout << "\nConnessione avvenuta\n";
cout << "host: " << host << "\n";
cout << "passw: " << db_pass << "\n";

res = mysql_use_result(conn);

/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
{
printf("%s \n", row[0]);
cout << row[0];
}

mysql_close(conn); // chiude la connessione

cout << "\nConnessione chiusa\n";
return 0;
}

All I get in the terminal is:

conn = 0xbfcf4038
Errore di connessione al database: Error: Can't connect to MySQL server on '127.1.0.1' (111)

Connessione avvenuta
host: 127.1.0.1
passw: gina
MySQL Tables in mysql database:
Segmentation fault
renzo01@renzo01-laptop:~/software/cpp/2010$

Any suggestion?

Thank you in advance!:cry:

AlucardZero 09-05-2010 11:13 PM

you marked the thread solved, how did you solve this?

renzorizzato 09-07-2010 03:32 PM

Idiot twice
Wrong answer in the wrong place, anyway, I wrote the wrong IP into the code: 127.1.0.1 instead of 127.0.0.1 :
using namespace std;

MYSQL_RES *res;
MYSQL_ROW row;

const char *host = "127.0.0.1";
const char *database = "matrici";
const char *db_user = "renzo01";
const char *db_pass = "gina";

int main (void) {
cout << "\033[2J" << "\033[0;0f";

MYSQL mysql;
MYSQL *conn;


All times are GMT -5. The time now is 12:18 AM.