This article illustrates how to access to local or remote MySQL server from the client API in Python, C and PHP.

Refer to MySQL server installing and test to install a MySQL server on your CORE9G25 Board with the database used on this examples.

Connecting to MySQL server with Python

Install MySQLdb module from Debian repository by typing:

debarm:~# apt-get install python-mysqldb

The try this example:, Position: CD:\\Debian\playground\python\mysql\

import MySQLdb


cur = db.cursor()
cur.execute("SELECT * FROM addressbook;")

rows = cur.fetchall()

for row in rows:
    print row


debarm:~# python 
(1L, 'CORE9G25 Systems srl', '+39 (06) 99-12-187', '')
(2L, 'Atmel Corporate', '+1 (408) 441-0311', '')
(3L, 'Digikey', '+1 (800) 344-4539', '')
(4L, 'Mouser', '+39 02 575 065 71', '')

Connecting to MySQL server with C

Install MySQL C client library from Debian repository by typing:

debarm:~# apt-get install libmysqlclient-dev

The try this example:

addrlist.c,  Position: CD:\\Debian\playground\python\mysql\addrlist.c

#include "mysql/mysql.h"
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"    
#include "fcntl.h"  

int main(int argc, char **argv)
    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW row;
    int num_fields;
    int i;

    if ((conn = mysql_init(NULL))==NULL) {
        fprintf(stderr, "Failed on mysql_init()\n");

    if (mysql_real_connect(conn, "", "root", "CORE9G25", "mydb", 3306, NULL, 0)==NULL) {
        fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(conn));

    if (mysql_query(conn, "SELECT * FROM addressbook")!=0) {
        fprintf(stderr, "Failed on SQL Query: %s\n", mysql_error(conn));

    result = mysql_store_result(conn);

    num_fields = mysql_num_fields(result);

    while ((row = mysql_fetch_row(result))) {
        for(i = 0; i < num_fields; i++) {
            printf("%s ", row[i] ? row[i] : "NULL");

Compiling it in this way:

debarm:~# gcc addrlist.c -lmysqlclient -o addrlist
debarm:~# ./addrlist
1 CORE9G25 Systems srl +39 (06) 99-12-187 
2 Atmel Corporate +1 (408) 441-0311 
3 Digikey +1 (800) 344-4539 
4 Mouser +39 02 575 065 71

Connecting to MySQL server with PHP

Install the PDO driver:

debarm:~# apt-get install php5-mysql

Restart lighttpd web server:

debarm:~# /etc/init.d/lighttpd restart

Save in /var/www/ the following PHP script:

addrlist.php, Position: CD:\\Debian\playground\python\mysql\addrlist.php

Position: CD:\\Debian\playground\python\mysql\addrlist.php

Open a browser on the following url:

We suggest to enable the display_errors parameter on line 531 of /etc/php5/cgi/php.ini file during the development:

display_errors = On

and restart the lighttpd web server:

debarm:~# /etc/init.d/lighttpd restart

Related links

Documentation Terms of Use
The Acme Systems srl provides this Debian system development and user manual.
The origin of these doc came from the website:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Creative Commons License

Market Mail :
Support Mail: Sales Phone: +86-755-29638421

CoreWind Online Chat>
Work time: 09:00-18:00
Copyright @ 2014 to 2020 - CoreWind Tech.