<< Chapter < Page Chapter >> Page >
mysql c api

Mysql c api


Przed uruchomianiem aplikacji natęży mieć bazę danych z tabela 'result' z polami: Id, Time, SP, PV, CV. Jeżeli sie takowej nie posiada należy ją stworzyć.

Oto kilka przydatnych do tego instrukcji:

połączenie z baza:

# mysql -u $user -p

tworzenie bazy danych:


pracuj z tabela (wykonuj na niej dalsze operacje):

>USE control

tworzenie tabeli:

>CREATE TABLE result(Id int not null auto_increment primary key,Time TimeStamp(14) not null,SP double not null,PV double not null,CV double not null );

dodawanie danych (Id i Time uzupełniane są automatycznie):

>INSERT INTO result (SP,PV,CV) VALUES(1,2,3)

czyszczenie tabeli:

>DELETE FROM result;

czyszczenie tabeli (Id zacznie numerować od nowa):

>TRUNCATE result;

usuwanie tabeli z bazy:

>DROP result;

zamiana nazwy kolumny:

>ALTER TABLE `result` CHANGE `number` `Id` DECIMAL( 9, 0 ) DEFAULT '0' NOT NULL;

zmiana hasła:

>SET PASSWORD FOR $user=PASSWORD('password');

C api

Przed połączeniem z baza danych należy inicjalizować strukturę – identyfikator:

mysql = mysql_init((MYSQL*) 0);

Połączenie z baza danych:

mysql_real_connect( mysql, host, login, passwd, table, port,NULL,0);

Wykonanie zapytania:

mysql_real_query(mysql,query,(unsigned int) strlen(query));

Zamykanie połączenia:


Jeżeli chcemy pobrać rezultaty zapytania np. po pytaniu “SHOW” lub “SELECT” należy użyć dodatkowych funkcji.

Używaj rezultatów ostatniego zapytania:


Wyodrębnij nazwy kolumn:

fields = mysql_fetch_fields(res);

Pobierz wiersz spełniający ostatnie zapytanie (konwersja rezultatów w krotki):

row = mysql_fetch_row(res);

Wyodrębnij liczbe kolumn:

num_fields = mysql_num_fields(res);

Wyodrębnij szerokości kolumn:

lengths = mysql_fetch_lengths(res);

Specyfikacja zmiennych i funkcji mysql c api

MYSQL-struktura komunikacyjna:

typedef struct st_mysql {

NET net; /* Communication parameters */

gptr connector_fd; /* ConnectorFd for SSL */

char *host,*user,*passwd,*unix_socket,


unsigned int port,client_flag,server_capabilities;

unsigned int protocol_version;

unsigned int field_count;

unsigned int server_status;

unsigned long thread_id; /* Id for connection in server */

my_ulonglong affected_rows;

my_ulonglong insert_id; /* id if insert on table with NEXTNR */

my_ulonglong extra_info; /* Used by mysqlshow */

unsigned long packet_length;

enum mysql_status status;

MYSQL_FIELD *fields;

MEM_ROOT field_alloc;

my_bool free_me; /* If free in mysql_close */

my_bool reconnect; /* set to 1 if automatic reconnect */

struct st_mysql_options options;

char scramble_buff[9];

struct charset_info_st *charset;

unsigned int server_language;


MYSQL_RES -struktura reprezentująca rezultaty zapytania

typedef struct st_mysql_res {

my_ulonglong row_count;

unsigned int field_count, current_field;

MYSQL_FIELD *fields;


MYSQL_ROWS *data_cursor;

MEM_ROOT field_alloc;

MYSQL_ROW row; /* If unbuffered read */

MYSQL_ROW current_row; /* buffer to current row */

unsigned long *lengths; /* column lengths of current row */

MYSQL *handle; /* for unbuffered reads */

my_bool eof; /* Used my mysql_fetch_row */


MYSQL_ROW-struktura reprezentująca danych w krotce.

typedef struct st_mysql_field {

char *name; /* Name of column */

char *table; /* Table of column if column was a field */

char *def; /* Default value (set by mysql_list_fields) */

enum enum_field_types type; /* Type of field. Se mysql_com.h for types */

unsigned int length; /* Width of column */

unsigned int max_length; /* Max width of selected set */

unsigned int flags; /* Div flags */

unsigned int decimals; /* Number of decimals in field */


Plik nagłówkowy mysql znajduje sie w /usr/include/mysql :



MYSQL *STDCALL mysql_init(MYSQL *mysql);

MYSQL *STDCALL mysql_real_connect(MYSQL *mysql, const char *host,

const char *user,

const char *passwd,

const char *db,

unsigned int port,

const char *unix_socket,

unsigned int clientflag);

void STDCALL mysql_close(MYSQL *sock);

int STDCALL mysql_real_query(MYSQL *mysql, const char *q,unsigned long length);

MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);

MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);

unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);

MYSQL_FIELD *STDCALL mysql_fetch_field(MYSQL_RES *result);

unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);






# gcc -lm -lmysqlclient zbiornik_mysql.c regul.c mylib.c -o zbior

katalog zbr2

zawiera zrodal programu ktory wykonuje:

  • polczenie z baza
  • symulacje zbiornik-regulator
  • zapis przebiegu Temperatury do bazy
  • odczytanie i wypisanie na ekran zpisanych danych z bazy

katalog zbr3

zawiera zrodal programu ktory wykonuje:- polczenie z baza

  • symulacje zbiornik-regulator
  • zapis przebiegu Temperatury do bazy
  • odczytanie i wypisanie na ekran zpisanych danych z baz
  • mozliwosc samodzielnego wykonania zapyt. do bazy- skł MySQL

Uwaga odczyt rezultatow nie jest doskonaly, np wysypuje sie przy pytaniu SLECT... zadanym gdy tabela jest pusta

Questions & Answers

how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Do somebody tell me a best nano engineering book for beginners?
s. Reply
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
many many of nanotubes
what is the k.e before it land
what is the function of carbon nanotubes?
I'm interested in nanotube
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
what is system testing
what is the application of nanotechnology?
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
anybody can imagine what will be happen after 100 years from now in nano tech world
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
silver nanoparticles could handle the job?
not now but maybe in future only AgNP maybe any other nanomaterials
I'm interested in Nanotube
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
can nanotechnology change the direction of the face of the world
Prasenjit Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
QuizOver.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Algorytmy i struktury komputerowych systemów sterowania. OpenStax CNX. May 22, 2007 Download for free at http://cnx.org/content/col10420/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Algorytmy i struktury komputerowych systemów sterowania' conversation and receive update notifications?