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;
}
gcc -o output $(mysql_config --cflags) test_mysql.c $(mysql_config --libs)
./output