• Articles / Artículos
  • Contact / Contacto
CODEANDO : our blog about technology

Connect to MySQL from a C program in QNX

28/7/2016

0 Comments

 
If you need to install MySQL on QNX see this post.

Once you started mysqld, you can connect to your databases from any program.
​
To test your connection and query from a C program in QNX, you can create a file (for example test_mysql.c) with the following content:
#include
#include
int main(int argc, char *argv[]) {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "12345"; /* Replace with your password */
char *database = "mysql";
conn = mysql_init(NULL);
/* Connect to mysql */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
return 1;
}
/* run SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
return 1;
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
return 0;
}
​In order to compile this example and link to mysql libraries, run the following command:
gcc -o output $(mysql_config --cflags) test_mysql.c $(mysql_config --libs)
To execute the test application, run:
./output
Picture
This post is published by the developer's team at INNVAS SRL. If you have any comments, suggestions or requests, please feel free To contact us. Thanks for stopping by!

0 Comments



Leave a Reply.

    Picture

    Authors

    We are the development team at INNVAS SRL, a nice group of engineers and IT specialists with solid experience in software development on different platforms, most of them custom developments, for different areas and industries. Our experience includes real time systems (automation and control), SCADA systems, drivers and protocols, GIS, image processing, simulation and optimization, web portals, mobile applications, embedded solutions, among others. 
    We enjoy working on different hardware and software platforms (Windows, Linux, QNX, Android, iOS , Raspberry Pi) and technologies (.NET, Java, HTML5,  C / C ++, Python, Matlab, CUDA, among others).

    Categories

    All
    Apache
    Linux
    MySQL
    Netbios
    Networking
    OpenTSDB
    PHP
    QNX
    Raspberry Pi
    Samba
    Ubuntu

    Archives

    July 2016
    June 2016
    May 2013

    Ads

    Consulting

    Picture
    Need support in QNX ?

    Apache on QNX
    Open SSL on QNX
    MySQL on QNX
    PHP 5 on QNX
    Open LDAP on QNX

    Contact us at:


    INNVAS SRL
    Montevideo
    Uruguay
    ​www.innvas.com
    info@innvas.com


    QNX is a trademark of
    ​QNX Software Systems
Powered by Create your own unique website with customizable templates.