On Tue, 5 Mar 2002 [EMAIL PROTECTED] wrote:
> I'm trying to understand how can I use 'C' programs accessing a MySql
> DataBase, please, could you send me a small program or so that creates
> a Table or two and make some changes on them. I read so many examples
> but all of them only contain parts of the code. please... help...what
> library I must include...
Alexandre
there was an example on this list quite recently. It was a complete piece
of code showing how to insert image files into blob columns. This will get
you started.
Thomas
---- quote
From: paradoxix <[EMAIL PROTECTED]>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/fcntl.h>
#include <mysql/mysql.h>
MYSQL dbcon;
int main(int argc, char *argv[])
{
int i;
char *tmpQ=malloc(2*1024*1024);
char *end;
int file;
int size;
char *mem;
char tmpstr[1024];
mysql_init(&dbcon);
mysql_real_connect(&dbcon, NULL, "username", "password",
"dbname",0,"/tmp/mysql.sock",0);
for(i=1;i<argc;i++) {
file = open(argv[i], O_RDONLY);
lseek(file, 0, SEEK_SET);
size = lseek(file, 0, SEEK_END);
lseek(file, 0, SEEK_SET);
mem = malloc(size);
read(file,mem,size);
printf("inserting: %s\n",argv[i]);
end = (char *) strmov(tmpQ,"INSERT INTO image values(");
*end++ = '\'';
sprintf(tmpstr,"%i",i);
end = strmov(end, tmpstr);
*end++ = '\'';
*end++ = ',';
*end++ = '\'';
sprintf(tmpstr,"%i",i);
end = strmov(end, tmpstr);
*end++ = '\'';
*end++ = ',';
*end++ = '\'';
end += mysql_escape_string(end, mem, size);
*end++ = '\'';
*end++ = ')';
mysql_real_query(&dbcon, tmpQ, (unsigned int) (end - tmpQ));
free(mem);
close(file);
}
mysql_close(&dbcon);
exit(0);
return 0;
}
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php