// Collection of code snippets by Arne VajhÃ¸j 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
#include <stdio.h>
#include <stdlib.h>

#include "mysql.h"

int main()
{
    /* connection */
    MYSQL *handle;
    /* SQL kommando */
    char sqlcmd[200];
    /* counter */
    int i;
    /*
     * åben connection til:
     *   server = "localhost"
     *   username = "root"
     *   password = ""
     *   database = "Test"
     *   port = 0 (bliver opfattet som default 3306)
     */
    handle= mysql_init(NULL);
    if(handle == NULL)
    {
        printf("MySQL error: %s", mysql_error(handle));
        exit(1);
    }
    if(!mysql_real_connect(handle, "localhost", "root", "", "Test", 0, NULL, 0))
    {
        printf("MySQL error: %s", mysql_error(handle));
        exit(1);
    }
    /* indsæt 10 rækker */
    for(i=0; i<10; i++)
    {
        sprintf(sqlcmd, "INSERT INTO t1 VALUES (%d,'%s')", i, "Dette er en test");
        mysql_query(handle, sqlcmd);
    }
    /* luk connection */
    mysql_close(handle);
    return 0;
}
