nc3b
nc3b

Reputation: 16270

C application libmysqlclient versus ODBC

I am writing an application that needs to interface with a MySQL database. Should I use libmysql or the ODBC connector ? Are there any pros / cons beside the fact that using ODBC will allow me to change the DB in the future without much code change ?

Upvotes: 2

Views: 564

Answers (2)

Pete Wilson
Pete Wilson

Reputation: 8704

I change my DB all the time, and I use the C connector, which works flawlessly and without too much code change. That has been the better choice for me and, perhaps, for you ( of course only imo).

I can't believe that code changes would be much different between the two interfaces, iff you are going to stick with MySQL.

EDIT: I chose the C connector originally because it was intuitive and natural for me; and because I wasn't too sure that there was a working, hardened ODBC for Linux: my code has to run under both Windows and Linux. Now I see that there is indeed such a thing. That makes ODBC more attractive: maybe I would have chosen differently if I'd known about it.

Upvotes: 2

Philip
Philip

Reputation: 5917

In my opinion, it's a matter of personal preference.

When using libmysql, a good approach would be to first write a set of generic libmysqlclient wrapper functions (layer A), above that a set of functions that implement the database functionality that you're going to use in your program (layer B), and above that your actual program (layer C).

Switching from libmysql to ODBC only requires minor changes in layer B without modifying layer B's API. Hence, if you intend to use your program with MySQL only, I'd suggest that you stick with libmysql until someone provides you with a patch for ODBC.


On the technical side, you have to make a trade-off between database connectivity and portability. Using libmysql enables your code to compile without modifications on a variety of platforms, such as Unix, MacOS and Windows. ODBC libraries are typically written either for Windows or for Unix/MacOS.

Upvotes: 2

Related Questions