MySQL Forums
Forum List  »  Spanish

Coneccion a Mysql en C
Posted by: Edwin Solorzano
Date: November 21, 2006 05:30PM

Hola,

trato de compilar el siguiente codigo:

/*---( test.c )----------------------------------------------*/

#include "/usr/include/mysql/mysql.h"
#include <stdio.h>

main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;

char *server = "mysql-server.ucl.ac.uk";
char *user = "ucabwww";
char *password = "secret";
char *database = "ucabwww";

conn = mysql_init(NULL);

/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}

/* send SQL query */
if (mysql_query(conn, "SELECT * FROM people WHERE age > 30")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}

res = mysql_use_result(conn);

/* output fields 1 and 2 of each row */
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s %s\n", row[1], row[2]);

/* Release memory used to store results and close connection */
mysql_free_result(res);
mysql_close(conn);
}

/*-------------------------------------------------*/


gcc test.c

y me genera los siguientes errores:
/tmp/ccop9u5C.o(.text+0x32): In function `main':
: referencia a `mysql_init' sin definir
/tmp/ccop9u5C.o(.text+0x52): In function `main':
: referencia a `mysql_real_connect' sin definir
/tmp/ccop9u5C.o(.text+0x67): In function `main':
: referencia a `mysql_error' sin definir
/tmp/ccop9u5C.o(.text+0x98): In function `main':
: referencia a `mysql_query' sin definir
/tmp/ccop9u5C.o(.text+0xad): In function `main':
: referencia a `mysql_error' sin definir
/tmp/ccop9u5C.o(.text+0xd9): In function `main':
: referencia a `mysql_use_result' sin definir
/tmp/ccop9u5C.o(.text+0xea): In function `main':
: referencia a `mysql_fetch_row' sin definir
/tmp/ccop9u5C.o(.text+0x125): In function `main':
: referencia a `mysql_free_result' sin definir
/tmp/ccop9u5C.o(.text+0x133): In function `main':
: referencia a `mysql_close' sin definir
collect2: ld devolvió el estado de salida 1

podrian decirme q estoy haciendo mal? :S

Edwin

Options: ReplyQuote


Subject
Views
Written By
Posted
Coneccion a Mysql en C
5374
November 21, 2006 05:30PM
2460
November 30, 2006 06:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.