List:MySQL++« Previous MessageNext Message »
From:Elizabeth Bonifacio Date:June 22 2005 10:07am
Subject:help to connect from c application
View as plain text  
I'm new into mysql and has been encountering huge problem in
connecting to the database from the c application. Error message is:
Failed to connect to database: Error:
Client does not support authentication protocol requested by server;
consider upgrading MySQL client
Press any key to continue

here is the application:
#include "stdio.h " 
#include "winsock.h" 
#include "iostream.h "

#include "mysql.h"

int main()
{ 

MYSQL mysql; 
MYSQL_ROW row; 
MYSQL_RES *result; 

unsigned int num_fields; 
unsigned int i; 
int num = 0;
int iRetValue = 0;

mysql_init(&mysql); 
//printf("%s",&mysql );

if (!mysql_real_connect(&mysql,"localhost","sampadm","secret","sampdb",3306,
NULL,0))
{ 
fprintf(stderr, "Failed to connect to database: Error: \n%s\n", 
mysql_error(&mysql)); 
} 
else 
{ 
printf("SUCCESS\n");
iRetValue = mysql_query(&mysql, "SELECT * FROM user");

if( iRetValue != 0 )
{
printf("Query Not Executed Properly.Please Check The Syntax.\n");
}
//here goes the error message :o) 
else
{ 
result = mysql_store_result(&mysql);

num = mysql_field_count(&mysql);
printf("Number Of Rows :%d\n",num );

num_fields = mysql_num_fields( result);
printf("Number Of Coloumns :%d\n",num_fields );

while ((row = mysql_fetch_row(result))) 
{ 
unsigned long *lengths; 
lengths = mysql_fetch_lengths(result); 

for(i = 0; i < num_fields; i++) 
{ 
printf("[%.*s] \t", (int) lengths[i], row[i] ? row[i] : "NULL"); 
} 
printf("\n"); 
} 
} 
}
} 

I would appreciate if you guys can help. thanks.

Elizabeth
Thread
help to connect from c applicationElizabeth Bonifacio22 Jun