Thread: using mysql with c++

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    137

    using mysql with c++

    I've installed the mysql server, but I can't really find any website that tells you how to use it with c++. I know I need to use the my_global.h and mysql.h but I also need to use a dll. I found a website that said all I have to do is link libmysql.dll to dev-cpp but it said I have to use pexports and I can't find any information about that at all. Then I have to use the dlltool and I can't find any information on that either. Does anyone know what I have to do to use mysql in a c++ compiled exe? I would really appreciate it if you could tell me where I could find something to walk me through this. Thank you for your time.

  2. #2
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    Hi! I browsed through the MySql site and saw this: MySQL++ hope that helps. I saw a little of docs, and seems simple to use.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I thought mysql was for storing data generated by web programs, e.g. php/Apache/mysql. How do you use mysql in a C++ application?

  4. #4
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    Hey! I was browsing again and saw that MySQL already has a C API =D. Acctualy it is needed to build the lib I told first. Here is its doc: MySQL C API. I downloaded mysql, and this lib come togheter.

    7stud, you can have a desktop application, like a bank system, or a rental agency, a store. Any application that you must store large amounts of data, like customer info, products, so on...

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Ok. I want to learn how to set up a C++ app with mysql, too.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    I know about the mysql api. But I don't know how to set it up with dev-cpp. I found this:
    Hi.

    Try with Dev-Cpp

    download pexports-043 (search in google) I don't know the site.

    ... and execute ...

    1. pexports libmysql.dll > libmysql.def
    2. dlltool comes with dev-cpp
    dlltool -k --input-def libmysql.def --dll-name libmysql.dll --output-lib libmysql.a
    3. create a project (with a source code), in project menu->project options->parameters->linker-> add -lmysql
    4. compile and link your program
    5. a error ocorred

    a unrecognized ... mysql_init@4

    or something like this.
    6. edit limysql.def and add @number in front of the function. Example:
    a unrecognized ... mysql_init@4
    in libmysql.def
    (you find like this)
    ...
    ...
    mysql_init
    ...
    ...
    (so)
    ...
    ...
    mysql_init@4
    ...
    ...

    save the file. execute dlltool again, and try compile/link,


    Bye
    The only problem is I don't know how to use the pexports or the dlltool. If anyone can say exactly how to do this that would be great. Thank you for your help.

  7. #7
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    Quote Originally Posted by 7stud
    I thought mysql was for storing data generated by web programs, e.g. php/Apache/mysql. How do you use mysql in a C++ application?
    mysql is just a database server that can be accesed by anything that has the ability to access it.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The only problem is I don't know how to use the pexports or the dlltool.
    Open a command line prompt and use from there.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    I got the libmysql.a created and linked into the project but now I need to know how to use MySql commands in c++. Is that what I need a wraper for? I downloaded mysql++ and tried to install it, because origionally thats what I thought I needed. But when I got to the make.mingw I couldn't figure out what to do next. So if anyone can tell me what to do after I've linked libmysql.a I'd really appreciate it. Thank you for your time.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You could use the MySQL C API with C++, but MySQL++ is probably the better option. Read the README.mingw file for instructions (you will probably have to use the command line).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    I followed the directions and I got an error saying dlltool: installation error, cannot exec 'as' I don't really understand what that means. I tried to google it but I didn't really find anything useful. Seems other people have had problems similar to this, but every page I checked never had an answer. Do you know of anything that causes this error, what this error means? Thank you for your time.

  12. #12
    Registered User
    Join Date
    Oct 2005
    Posts
    88
    There's no reason you can't use C++ for web applications 7stud. It's not even a stupid idea: writing code in one of the 'p's (-thon,-erl,-hp) isn't really that much faster, despite people always going on about it.

    yahn, on Windows I found it easier to just use the mysql c api, rather than Mysql++ (although apparently Mysql++ is good, I couldn't get it working properly). All you need to do is #include <winsock.h> before you #include <mysql.h>. Then you have to include the libraries wsock32.lib (or ws2_32.lib if you need winsock2 support) and mysqlclient.lib (there is another mysql library, but that one is probably the one you're going to want). Make sure you they will be found by the compiler and that should be it.

  13. #13
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    There's no reason you can't use C++ for web applications 7stud. It's not even a stupid idea: writing code in one of the 'p's (-thon,-erl,-hp) isn't really that much faster, despite people always going on about it.
    How?

  14. #14
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by 7stud
    How?
    all you need is a CGI library for C++ and a web server that supports it. a quick google turns up several libraries.

    That said, C++ really isn't designed for CGI. There's a reason that python, perl and php are more popular. they're better suited, (mature CGI libraries, better regex support) and easier to use (dynamic typing, no compile cycle). The price you pay is that they're slower, but if you spend 90% of the time waiting for a request, who cares?
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  15. #15
    Registered User
    Join Date
    Oct 2005
    Posts
    88
    You don't need anything, really. A CGI library isn't at all hard to write, but it's true that certain aspects of the p's are better suited. To be honest I don't see why having no compile cycle is of any significance, except that web apps in general aren't very mature, so development times need to be as short as possible. Remember that having an uncompiled web app is less secure than having a compiled one.

    For now though, it's like Chaos said: actual execution speed of your app isn't usually the bottleneck. I only choose to write mine in c++ because I prefer it.
    </offtopic banter>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change detection in MySQL.
    By amitbora27 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-13-2009, 10:34 AM
  2. MySQL libraries
    By csonx_p in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2008, 02:23 AM
  3. About C++ and MySQL or oether free database
    By xxxrugby in forum C++ Programming
    Replies: 18
    Last Post: 12-30-2005, 06:28 AM
  4. Get data from mysql and use in a system.
    By smaakage in forum Tech Board
    Replies: 3
    Last Post: 10-04-2005, 12:03 PM
  5. Get data from mysql and use in a system.
    By smaakage in forum C++ Programming
    Replies: 5
    Last Post: 10-02-2005, 01:25 PM