tags:

views:

56

answers:

2

This is pretty easy in PHP:

$con = mysql_connect("localhost:".$LOCAL_DB_PORT, $LOCAL_DB_USER, $LOCAL_DB_PASS);
mysql_select_db("db", $con);
mysql_query("set names utf8", $con);

$result = mysql_query("select ...");
while($row = mysql_fetch_assoc($result))
{
...
}

But what's the easiest way to do it with c/c++ in windows?

+1  A: 
MYSQL* mysql_connection_setup(struct connection_details mysql_details)
{
     // first of all create a mysql instance and initialize the variables within
    MYSQL *connection = mysql_init(NULL);

    // connect to the database with the details attached.
    if (!mysql_real_connect(connection,mysql_details.server, mysql_details.user, mysql_details.password, mysql_details.database, 0, NULL, 0)) {
      printf("Conection error : %s\n", mysql_error(connection));
      exit(1);
    }
    return connection;
}

For a working example take a look at: http://www.codingfriends.com/index.php/2010/02/17/mysql-connection-example/

Adnan
A: 

You need to get hold of MySql Connector/C++. Information on download and usage is here.

If licensing constraints prevent this, you can use Connector/ODBC.

Steve Townsend
Is there a connector in `c` ?
ollydbg
@ollydbg - yes, check out the docs at http://dev.mysql.com/doc/refman/5.1/en/c.html
Steve Townsend