3 messages in com.mysql.lists.mysqlHow to use C API
FromSent OnAttachments
Niedermayer Miklos01 Jun 2000 11:22 
sin...@mysql.com02 Jun 2000 05:51 
indrek siitan02 Jun 2000 14:00 
Subject:How to use C API
From:Niedermayer Miklos (mi@musician.org)
Date:06/01/2000 11:22:44 AM
List:com.mysql.lists.mysql

Hi!

Please help me to find out how to use a MySQL database from C/C++. I'm just learning and trying things to get to work, but i would be happy if you could help me.

My little C app is the following (for example):

------ #include <mysql/mysql.h> #include <stdio.h>

void main()

{ MYSQL * dbh; mysql_connect(dbh, "localhost", "user", "password"); // .... (not much else)

}

------

I tried to compile it with the following command:

gcc -L /usr/local/lib/mysql -lmysqlclient lamme.c

lamme.c: In function `main': lamme.c:6: warning: return type of `main' is not `int' /usr/local/lib/mysql/libmysqlclient.so: warning: tempnam() possibly used unsafely; consider using mkstemp()

I think it's okay, but when i run it, it just says 'bus error' and does some coredump.

(I'm using FreeBSD 4.0-RELEASE with MySQL 3.22.32, installed from package on the FBSD 4.0 CD)

I've never tried to use MySQL under C before so i probably have to learn a lot. :) I've successfully done it under PHP, Perl, and Python, and never had any problems. Personally I like Python best, it's very friendly to me and i can recommend it for everyone, but it's slow (on my P166/32M i can only do 3-4 dynamic HTML page generation per sec, and it isn't because the slowness of the computing, this is the case if the script contains just one line, 'print "Content-type: text/html\n\nHello world, hello girls!"'), it would be a good thing to convert some of my py-CGIs into C.

Thanks for you help in advance,

Mico