#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    19
    Rep Power
    0
    #include <stdio.h>
    #include <stdlib.h>
    #include "mysql.h"

    MYSQL mysql;
    MYSQL_RES *res;
    MYSQL_ROW row;

    void exiterr(int exitcode)
    {
    fprintf( stderr, "%sn", mysql_error(&mysql) );
    exit( exitcode );
    }

    int main()
    {
    uint i = 0;

    if (!(mysql_connect(&mysql,"host","username","password")))
    exiterr(1);

    if (mysql_select_db(&mysql,"ksedata"))
    exiterr(2);

    if (mysql_query(&mysql,"SELECT name,rate FROM emp_master"))
    exiterr(3);

    if (!(res = mysql_store_result(&mysql)))
    exiterr(4);

    while((row = mysql_fetch_row(res))) {
    for (i=0 ; i < mysql_num_fields(res); i++)
    printf("%sn",row[i]);
    }

    if (!mysql_eof(res))
    exiterr(5);

    mysql_free_result(res);
    mysql_close(&mysql);
    }


    ***************************************
    when i compile above code following error messages come

    undefined reference error mysql_connect(...)
    undefined reference error mysql_bin(..)
    etc...
    whats wrong either my gcc is not link whith
    client side lib or something else?
    thanks in advance..
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    What do your compiling and linking commands look like?

    Did you pass the the mysql.h header file argument and client library argument in the compiling and linking steps, respectively so the compiler and linker can find the files?

    Try something like....

    gcc -c -I/usr/local/include/mysql program.c

    gcc -o program program.o -L/usr/local/lib/mysql -lmysqlclient

Similar Threads

  1. Odd problem with a hash and foreach loop
    By quantumechanix in forum Perl Programming
    Replies: 7
    Last Post: December 15th, 2003, 05:06 PM
  2. Replies: 2
    Last Post: December 1st, 2003, 08:49 AM
  3. Replies: 0
    Last Post: May 24th, 2000, 07:56 AM

IMN logo majestic logo threadwatch logo seochat tools logo