Does anyone know of a simple way for a C++ program to communicate directly with a MySQL database? I have looked at MySQL++ and found it to be very confusing. If anyone knows of a very simple way of doing this, please let me know.
Thanks
P.S. I am developing on a Windows machine. PHP and MySQL web web application setup. C++ setup to talk to the serial port. Thus why I need a way for C++ to talk to the MySQL database directly.
There are quite a few database API wrappers but my favourite - and the one I recommend - is the SOCI library. Much nicer syntax than using the raw C API.
The 'motivating' example from the SOCI website:
int id = ...;
string name;
int salary;
sql << "select name, salary from persons where id = " << id, into(name), into(salary);
The C MySQL API is just like using the PHP MySQL extension and so should be pretty familiar. If you are comfortable with C, I'd recommend that (and you don't mind mixing C in your C++).
Use the C API:
http://dev.mysql.com/doc/refman/5.0/en/c.html
MySQL has a beta release of MySQL Connector C++ that can be found Here. It's a connector written in C++ but modeled after Java's JDBC connectors. If you've used JDBC at all, this will feel almost identical. It's also cross platform and can be compiled on Linux, Windows, and Mac OS.
I have used MySQL++ with great success. I found it to be everything I was looking for in a MysQL database client library. The examples they provide are great, see here for a simple one.
If you know C++, it is much easier to use than the C library. It works great with Windows.
Use SQLAPI++ - it does SQL Server and more.
http://www.sqlapi.com/
MySQL Connector/C++ is a C++ implementation of JDBC 4.0
The reference customers who use MySQL Connector/C++ are:
- OpenOffice
- MySQL Workbench
Learn more: http://forums.mysql.com/read.php?167,221298
Are you sure that the C++ program needs to interact directly with the MySQL database?
I would suggest having the C++ program communicate with the web server using simple http requests, and let PHP handle the database. Data can be passed to a server-side PHP script via arguments, and data can be returned in XML format.
Writing: your.server.com/add_data.php?table="info"&data="0xFCBD..."
Reading: your.server.com/get_data.php?table="info"
Related
I'm writting a tic-tac-toe game in c++ and I want to create a hight scores view. The problem is I'm new to DB and now just theory of SQL.
So, how can I add a simple SQL table to my c++ project?
(id INTEGER PRIMARY KEY, name TEXT, hightScore INTEGER)
Looks like just adding to project SQL script file and creating this table not gonna work. How to connect it with my cpp files? Where and how I'll be able to make an INSERT after each new game was played?
Thanks in advance!
To have a simple table you'll need to have a database to set the table up within. The library you will use to communicate with the database is going to depend on which database you are running.
Setting up the needed libraries usually means installing them and updating your linker. This will require some research and effort on your part to make it work, depending on what your particular configuration is.
some ideas:
(for mysql there is mysql/mysql.h which is a free library. )
How to make #include <mysql.h> work?
(for other SQL databases (not free))
http://www.sqlapi.com/
(possible free alternative to sqlapi )
Free alternative to SQLAPI++?
Hopefully that will get you started in the right direction! Good luck.
I have researched about c++ database connectivity and i could find following ways to connect to SQL server database from c++ project.
Using Microsoft's ODBC connection method. Which is a little bit complicate method and requires thorough research to use further.
Ref: https://www.techhowtos.com/programming/how-to-connect-to-sql-server-from-visual-c-plus-plus/
Using SQLAP++ Library which is very convenient way to connect to a databse . It Requires to purchase one time license to use commercially.
Using CPPCMS project's CppDB library.
Apologies if this is a bit of a vague question; I'll try to word it as appropriately as I can.
Basically I have a C++ application that currently runs off of a back-end MSSQL (SQL Server 2014) database. To ease in database communication and building the entity model we assembled our own set of C++ classes that wrap up the native ADO.NET calls; we have created it in such a way that the developer simply needs to supply details for a connection string and it is assembled as part of the connection method like so:
string.Format(_T("DRIVER=SQL Server;SERVER=%s\\%s;UID=%s;PWD=%s;DATABASE=%s"),string,strConnInstance,strUser,strPassword,strDatabase);
We now have a requirement to read from an oracle database, and we wonder if we can use the same connection libraries. I assume that we will need to tweak the connection string (e.e.g the driver would need to read something different). I believe I have read that Oracle connection can be faciliated through use of an ODBC driver? Would it simply be a case of installing the relevant driver (if so, which?) and changing the "Driver" argument in the connection string (if so, to what?).
If it is not quite this simple, is there any other way it can be done, or are we looking at a redevelopment?
Thanks in advance!
The answer is yes you can use ADO.NET to connect to Oracle. There's plenty of people out there on stack overflow already doing it...
https://stackoverflow.com/search?q=oracle+ado.net
Oracle has a page for the db provider...
http://www.oracle.com/technetwork/topics/dotnet/index-085163.html
Microsoft has a page talking about it...
https://msdn.microsoft.com/en-us/library/77d8yct7(v=vs.110).aspx
Oracle even has examples using Entity Framework...
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/EntityFrameworkOBE/EntityFrameworkOBE.htm
http://www.oracle.com/technetwork/issue-archive/2011/11-sep/o51odt-453447.html
There's heaps of resources out there.
I am trying to connect to oracle database using C code. Is it possible to use OCCI in the code? If yes please help me with some examples, please note it has to be C code.
If not what are the other options to connect to database using C.
OCCI is short for 'Oracle C++ Call Interface' and is targeted to C++ applications. If your application is going to be purely in C, then you should use OCI (Oracle Call Interface) instead as that is Oracle's call interface for applications written in C.
See the Programmer's guide for help and examples.
I'm using QT 5 with MingW 4.7 and i'm trying to start a program with an embedded mysql server.
My current program uses a mysql server, but the server has to be manually started (so out of the program). This isn't user friendly of-course.
I did some research and I need to use the libmysqld library . But I don't know how.
Can anyone give me an example how to use this?
You can use an embedded mysql server within Qt. There are no that many difficulties with that at all. If you could point any you faced I can help you with that, indeed you should link your application with libmysqld and then just start a mysql process within your application (there are plenty documentation available about that). But as was pointed in comments - are you sure you want to do that. There are many nicer embedded solutions available like SQLLite (included in Qt)...
Documentation and examples
You probably will need to have a look on mysql driver supplied with Qt and may be fork it for embedded version, but that needs a bit closer look. But again I don't see really issues with that
I am looking for a way to connect to an remote oracle database and read some data from table within a c++ console application.
Can some one give me some hints.
Thnx.
soci, http://soci.sourceforge.net, is a reasonably modern C++ interface that uses the Oracle call interface. And can also connect to other databases ...
The official Oracle website proposes several resources. Amongst others:
Oracle C++ Call Interface
Develop C and C++ Applications with Oracle Database 11g Using OCI
Just google, there are really plenty of tutorials around.
You can either use the Oracle C++ Call Interface (native API) or the Open DataBase Connectivity API. If you want a more high-level wrapper, there are some more convenient interfaces in libraries such as Qt.
Unless it's study purpose or strict requirement with ORACLE DB, I'd suggest you to work with generic classes/services provided with various Microsoft Framework.
Data Access Programming
MFC Database classes
ATL Database classes
Of course ORCACLE C++ IF is also available.
You can use OCCI: http://www.oracle.com/technetwork/database/features/oci/index-090820.html
or OCI: http://www.oracle.com/technetwork/database/features/oci/index.html
or one of many other APIs available.. It really depends on the type of thing you're going to use it for.. You should find a lot of information about the pros/cons of the various APIs through google..
You can try: CODBC. It is an API for Pro*C. Pro*C is a very decent way to connect Oracle and C++.
Currently (2021) actively developed is also OCILIB, I was able to setup the test example in short time.