Re: Encoding problem with C API
Posted by: n0000 n0000
Date: April 15, 2005 08:37AM

Thanks for the reply.

The result of the query SHOW VARIABLES LIKE 'character_set%' is as following,

character_set_client utf8
character_set_connection utf8
character_set_database latin1
character_set_results utf8
character_set_server latin1
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/

This result is obtained by using mysql query browser.

I tried to put mysql_query(mysql, "SET NAMES utf8") in the beginning of my application, but it seems not working. I attached my simple program below. Hope you can provide more information. Thanks a lot!

#include <stdio.h>
#include </usr/include/mysql/mysql.h>
#include <wchar.h>

#define HOST "localhost"
#define USER "webot"
#define PASSWD "5535990"
#define DB_NAME "webcache"

int
main (int argc, char *argv[])
{
MYSQL *mysql = NULL; // Connection handler
MYSQL_RES *result;
MYSQL_ROW row;
int len, i;
short *data;
wchar_t *out;
int fp;


mysql = mysql_init (NULL);

if (mysql == NULL)
return 1; // Init failed.

if (!mysql_real_connect
(mysql, HOST, USER, PASSWD, DB_NAME, MYSQL_PORT, NULL, 0))
return 1; // Connection failed.

mysql_query(mysql, "SET NAMES utf8");

if (mysql_query (mysql, "select title from taohuayuan") != 0)
return 1; // Select failed

result = mysql_use_result (mysql);

while ((row = mysql_fetch_row (result))){

printf("%s\n",out);

if (mysql_errno (mysql)) // Error when fetching rows
return 1;
}

mysql_free_result (result);

mysql_close (mysql);

return 0;
}

Options: ReplyQuote


Subject
Views
Written By
Posted
7424
April 10, 2005 08:52AM
Re: Encoding problem with C API
6321
April 15, 2005 08:37AM
6056
September 23, 2005 12:47AM
3694
November 27, 2005 12:33AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.