GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Jan-2009, 05:52
alin19 alin19 is offline
New Member
 
Join Date: Jan 2009
Posts: 1
alin19 is on a distinguished road

Connecting to MySQL with C++


hello guys, i'm new with c++; and i'm trying to make a connexion with mysql

i have read some tutorials but can't find anything that tells me what to download
how to include that file in my program and then how to connect, just find a lot of scripts that have errors
CPP / C++ / C Code:
#include "cmdline.h"
#include "printdata.h"
#include <mysql++.h>
#include <iostream>
#include <iomanip>

using namespace std;

int
main(int argc, char *argv[])
{
    // Get database access parameters from command line
    const char* db = 0, *server = 0, *user = 0, *pass = "";
    if (!parse_command_line(argc, argv, &db, &server, &user, &pass)) {
        return 1;
    }

    // Connect to the sample database.
    mysqlpp::Connection conn(false);
    if (conn.connect(db, server, user, pass)) {
        // Retrieve a subset of the sample stock table set up by resetdb
        // and display it.
        mysqlpp::Query query = conn.query("select item from stock");
        if (mysqlpp::StoreQueryResult res = query.store()) {
            cout << "We have:" << endl;
            for (size_t i = 0; i < res.num_rows(); ++i) {
                cout << '\t' << res[i][0] << endl;
            }
        }
        else {
            cerr << "Failed to get item list: " << query.error() << endl;
            return 1;
        }

        return 0;
    }
    else {
        cerr << "DB connection failed: " << conn.error() << endl;
        return 1;
    }
}

tangentsoft.net

and a lot more that are useless
can you help me, a simple example to execute a simple query "select * from `clients`" after that i will figure it out
i'm using windows xp and dev-c++ 4.9.9.2
  #2  
Old 22-Jan-2009, 06:16
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 226
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: connecting to mysql with c++


Why not just #include <mysql.h> and go at it using the C API? There are some excellent examples from MySQL's site/documentation/example code, etc.


MxB
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving data from MySQL to MySQL meurer MySQL / PHP Forum 0 25-Jan-2007 10:03
Cpanel downgrade MYSQL 4.1.X to MySQL 4.0.xx Webhosting-live Web Hosting Forum 1 01-Sep-2006 03:54
Trouble connecting to MySQL djd@n MySQL / PHP Forum 7 28-Oct-2005 09:10
Error connecting to MySQL Kilgayne MySQL / PHP Forum 4 27-May-2005 14:45

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:37.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.