#include #include #include #include int main(){ MYSQL mysql; int ret= 1; if(mysql_init(&mysql)==NULL){ fprintf(stderr, "Failed to initate MySQL connection\n"); exit (1); } if(mysql_real_connect(&mysql,"localhost","miracee","","test",0,NULL,0) == NULL) { fprintf(stderr, "Real connection failed\n"); exit (1); } printf("\nConnected\n"); /* utf8 encoding */ ret= mysql_query(&mysql, "set names utf8"); if(ret != 0){ fprintf(stderr, "Failed to set names utf8\n"); exit (1); } printf("names set to utf8\n"); /* just as information */ printf("MySQL server version is %s\n",mysql_get_server_info(&mysql)); /* create a test database */ ret= mysql_query(&mysql, "create database if not exists utf8capitest character set utf8 collate utf8_unicode_ci"); if(ret != 0){ fprintf(stderr, "Failed to create database utf8capitest\n"); exit (1); } printf("Database utf8capitest created\n"); /* create a test table */ ret= mysql_query(&mysql, "create table if not exists utf8capitest.utf8(id serial, t text, v varchar(100), c char(100), primary key(id))"); if(ret != 0){ fprintf(stderr, "Failed to create talbe utf8\n"); exit (1); } printf("Table utf8 created\n"); /* insert data */ ret= mysql_query(&mysql, "insert into utf8capitest.utf8(t, v, c) values ('äöüß','äöüß','äöüß')"); if(ret != 0){ fprintf(stderr, "Failed to insert first data row\n"); exit (1); } printf("inserted äöüß into utf8capitest.utf8\n"); ret= mysql_query(&mysql, "insert into utf8capitest.utf8(t, v, c) values ('ÄÖÜSZ','ÄÖÜSZ','ÄÖÜSZ')"); if(ret != 0){ fprintf(stderr, "Failed to insert second data row\n"); exit (1); } printf("inserted ÄÖÜSZ into utf8capitest.utf8\n"); mysql_close(&mysql); return 0; }