How to compile MySQL C client API

This tutorial shows how to compile the MySQL 5.0.21 C client API for the FOX Board

MySQL (http://www.mysql.org) is one of the most used and faster SQL server in the world.
MySQL C client API ( http://dev.mysql.com/doc/refman/5.0/en/c.html ) are a set of functions in C that enable your C applications to make SQL queries to a remote MySQL Server across a TCP/IP connection.

Using the MySQL C client API on the FOX Board it is possible to build a powerful gateway between external devices like lights, switches, display, etc. and the values stored in a SQL database.

An example is to generate an SQL "INSERT" every time a switch is pressed or show the results of a complex SQL "SELECT" directly on a LCD display to see the live values of total sales amounts from your ecommerce site.

How to compile step by step the MySQL C API on the FOX SDK

Example 1 - An event logger

In this example we'll generate on the MySQL server one record each time we push an external switch. The record will have a timestamp to know when the switch was pressed.

A led will indicate if the new log record has generated on the MySQL server with a single blink. More blinks indicate an error condition.

Build the hardware

The external switch is connected to the FOX Board as shown on the following schematic diagram:

Schematic to connect an external switch

Schematic to connect an external LED

Create database and table on the MySQL server

Create a new database named logger on your MySQL server and a table named switch inside it. Create inside the table switch four fields: id, time, switchid and description.

To create all of them you can use directly this SQL commands file: @source='logger.sql'

Be shure that your MySQL server is enabled to receive external transactions. To do that modify this line on /etc&msql/my.cnf:

#skip-external-locking
in
skip-external-locking
Be shure also that you server can accept connection on default MySQL port 3306.

This is the source of logger.c: @source='logger.c'

This is the result thet we obtain in the switch table:

mysql> select * from switch;
+----+----------------+----------+----------------+
| id | time           | switchid | description    |
+----+----------------+----------+----------------+
|  1 | 20060530074807 | IOG16    | Switch pressed |
|  2 | 20060530074809 | IOG16    | Switch pressed |
|  3 | 20060530074811 | IOG16    | Switch pressed |
|  4 | 20060530074812 | IOG16    | Switch pressed |
|  5 | 20060530074813 | IOG16    | Switch pressed |
|  6 | 20060530074813 | IOG16    | Switch pressed |
|  7 | 20060530074814 | IOG16    | Switch pressed |
|  8 | 20060530074815 | IOG16    | Switch pressed |
|  9 | 20060530074815 | IOG16    | Switch pressed |
+----+----------------+----------+----------------+
9 rows in set (0.00 sec)

Related links