1.how to connect database in c and c++2.what is CGI? 3.c and c+++ how to act in CGI?

Showing Answers 1 - 3 of 3 Answers

PRANAV WAILA

  • Oct 3rd, 2006
 

1. USE CGI SCRIPTING.

  Was this answer useful?  Yes

binny

  • Oct 28th, 2006
 

hi please....

can anyone help m out in giving clear explanation in this.....

waiting 4 ur help.........

  Was this answer useful?  Yes

Hi Binny

Please find the two files test.c and Makefile file for make a connection with test database in mysql.

test.c

#include <stdio.h>
#include <time.h>
#include <math.h>
#include </usr/include/mysql/mysql.h>
#include <stdarg.h>

MYSQL_RES *result;
MYSQL_ROW row;
MYSQL *connection, mysql;
int state;
char sql[512] = "";

main()
{

    mysql_init(&mysql);         /* connect to the mySQL database at localhost */

    connection = mysql_real_connect(&mysql,"localhost","root", "root","test", 0,NULL, 0);
                    /* check for a connection error */
    if( connection == NULL ) {
                                 /* print the error message */
    printf(mysql_error(&mysql));
    return;
    }

    sprintf(sql, "select * from emp");
    state=mysql_query(connection, sql);

    result = mysql_store_result(connection);
    while( row = mysql_fetch_row(result) ) {
        printf("%s %s n", row[0], row[1]);
    }
    mysql_close(connection);        /* close the connection */
    return ;
}

Binny make sure one thing when u compile your program, then you must compile with following types.

Makefile

CC  =gcc
INCLUDES    =-I/usr/include/mysql
LIBS    =-L/usr/lib/mysql   -lmysqlclient

all: myclient

test.o: test.c
    $(CC)   -c  $(INCLUDES) test.c

myclient: test.o
    $(CC)   -o  test    test.o  $(LIBS)

clean:
    rm  -f  test    test.o

After creating these file give command on linux prompt.

# make clean

# make

# ./test

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions