Posted By: chomer () on 'CZdatabases'
Title: Re: C+MySql
Date: Fri Jun 22 11:25:22 2001
>
>
> jasne ... z perlu je to v dobry ... me ale spis zajimalo to C ...
> x-max
>
Taky bych rad vedel..
zatim jsem se dostal k necemu takovemuto (bohuzel nikde zadny tutorial neni
:-((, vsechno jsem zkousel pomoci cteni hlavickovych souboru... :-o)
------------------- insert.c -----------------------------------------------
#include <stdlib.h>
#include <mysql/mysql.h>
int main () {
MYSQL *m;
m=mysql_init(NULL);
m=mysql_connect(m,"localhost","root","");
if (!m) {printf(":-("); return -10;}
mysql_select_db(m,"test");
mysql_query(m,"insert into ctest values('hee','huu','hoo')");
mysql_close(m);
return 0;
}
------------------ list.c (tady jsem nejak nenasel, jaxe dostat k hodnotam :(--
#include <stdio.h>
#include <stdlib.h>
#include <mysql/mysql.h>
int main () {
MYSQL *m;
MYSQL_RES *re;
int i,n,nn;
printf(".");fflush (stdout);
m=mysql_init(NULL);
m=mysql_connect(m,"localhost","root","");
if (!m) {printf(":-(n"); return -10;}
mysql_select_db(m,"test");
i=mysql_query(m,"select * from ctest");
if (i) {printf(":-((n"); return -20;}
re=mysql_store_result(m);
if (!re) {printf(":-(((n"); return -30;}
n= mysql_num_rows(re);
if (!n) {printf(":-((((n"); return -40;}
nn=mysql_num_fields(re);
printf(" %ld x %d n",n,nn);
mysql_close(m);
return 0;
}
-----------------------Makefile--------------------------------------
LFLAGS=-L/usr/lib/mysql
CC=gcc
CFLAGS=-O6
OPT=$(CFLAGS) $(LFLAGS)
LIBS=-lmysqlclient
all: insert list
insert: insert.c
$(CC) $(OPT) $@.c -o $@ $(LIBS)
list: list.c
$(CC) $(OPT) $@.c -o $@ $(LIBS)
---------------------------------------------------------------------
~
Chomer (chatid: opat)
Nesnasim turisticke znacky, nenavidim minova pole a miluju poust....