MySQL Connection

Hey all,

I’m starting a new project on QNX, and one thing this project will need is a database. I’ve decided to use MySQL, which I have installed and running on my QNX machine. Now I’ve created some tables and want to connect to MySQL with my QNX program (note that I’m still learning all this, so this is a dummy program, but this is how I intend to program the project).

So, anyone know of where I can find documentation or examples on how to connect to MySQL using QNX? I’m coding in C, and have not found any tutorial/examples that show how to connect to a MySQL database…

Thanks,

Dan…

The MySQL C library works the same on QNX as it does on other platforms, so a tutorial like this:

blog.rsynnott.com/2006/02/16/sim … -tutorial/

will probably work fine for you.

Cheers

Garry

kitebird.com/mysql-book/ch06-3ed.pdf
kitebird.com/mysql-book/ch06-1ed.pdf

And for C++, use a wrapper like:
alhem.net/project/mysql/

my 2 cents,
Freddy

Hi Dan,
Are you using MySQL on QNX6 or QNX4 ?
I am looking for mysqlclient library port to QNX4.
Do you know something about?

Thanks,

koko

Thansk for the links, I’ve got some reading to do!

I’m doing this project on QNX 6, and I am learning, so I wouldn’t be of much help at the moment ot answer your question Koko, sorry!

Alright, well I’ve read, and now I’m trying, and I seem to be getting some sort of problem. Btw, I’m using Momentics 6.3.0 to develop this program…

Ok, so I’m trying to create a connect.c file that will connect to my mysql server on my QNX machine. The code that I have is taken from one of the documents offered in previous posts in this topic. Here’s what I have:

The problem I’m getting is that I’m referencing functions from my included .h files (mysql_init, mysql_real_connect and mysql_close). I can find these funcitons in the .h files included in my program, but when I compile, I get undefined references for these calls.

Any one know whats going on?

Dan…

Heres the code:

#include <stdlib.h>
#include <stdio.h>
#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>

static char *opt_host_name = NULL;  	/* server host (default=localhost) */
static char *opt_user_name = NULL;  	/* username */
static char *opt_password = NULL;  		/* password (default=none) */
static unsigned int opt_port_num = 0;  	/* port number */
static char *opt_socket_name = NULL;  	/* socket name */
static char *opt_db_name = NULL;  		/* database name */
static unsigned int opt_flags = 0; 			/* connection flags (none) */

static MYSQL *conn;								/* Pointer to connection handler */

int main(int argc, char *argv[]) {

	/* initialize connection handler */
	conn = mysql_init(NULL);
	if (conn == NULL) {
		printf("mysql_init() failed (probably out of memory) \n");
		exit(1);
	}
	
	/* connect to server */
	if (mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password, opt_db_name, opt_port_num, opt_socket_name, opt_flags) == NULL) {
		printf("mysql_real_connect() failed \n");
		mysql_close(conn);
		exit(1);
	} else {
		printf("We have connected to mysql! \n");
	}
		
	/* disconnect from server */
	mysql_close(conn);
	exit(0);
//	return EXIT_SUCCESS;
}

Ive made some progress since this morning. Figured out that I needed to include the library path in my Linker options. Although I found where I needed to put the -L stuff, Im not sure where to put the -I stuff…

And now I get a different kind of message (as shown below), if anyone knows how to fix this, would be a great help.

A reminder that I`m using QNX Momentics 6.3.

This is what my console gives me when I try to build…

Looking at your output, I see you have -L/usr/include/mysql. Are you sure your mysql libraries are in /usr/include/mysql? Shouldn’t it be /usr/lib/mysql ? Check your mysql installation and find out the directory where the mysql libraries are.

I’ve never seend mysql server been ported to QNX 4, but for the mysqlclient library, it is a different story. It should be pretty easy to port, and I’ve seen other people had it done in the past.
Good luck!

Ok! So i’ve figured out how to correctly import all library files and everything, and it works!

That is it used to work… Now, for some reason, I get a
" mysql_real_connect() failed Error 2004: Can’t create TCP/IP socket (12) "…
:frowning:

I don’t understand why I get his error now, because I used to be able to connect to mysql and run queries! Anyone know what this means and what I can do about it?

Ok well, I’ve tried reinstalling everything and it all works now. :slight_smile:

I have to admit I’m surprised at how sensitive QNX is to being shut down improperly because it would seem that my computer was turned off without a proper shutdown, which corrupted the MySQL database in use. Will everything get corrupted again if there is ever a power outage?

If so, how do you guys handle such a possibility? Daily backups, ups…?