用C代码连接mysql,网上看到的例子,代码如下#include <stdio.h>
#include <stdlib.h>#include "mysql.h"
#include <windows.h>// just going to input the general details and not the port numbers
struct connection_details
{
  char *server;
  char *user;
  char *password;
  char *database;
};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;
}MYSQL_RES* mysql_perform_query(MYSQL *connection, char *sql_query)
{
  // send the query to the database
  if (mysql_query(connection, sql_query))
  {
  printf("MySQL query error : %s\n", mysql_error(connection));
  exit(1);
  }  return mysql_use_result(connection);
}int main()
{
  printf("Hello world!\n");  MYSQL *conn;  // the connection
  MYSQL_RES *res; // the results
  MYSQL_ROW row; // the results row (line by line)  struct connection_details mysqlD;
  mysqlD.server = "localhost"; // where the mysql database is
  mysqlD.user = "user";  // the root user of mysql
  mysqlD.password = "pws"; // the password of the root user in mysql
  mysqlD.database = "database"; // the databse to pick  // connect to the mysql database
  conn = mysql_connection_setup(mysqlD);  // assign the results return to the MYSQL_RES pointer
  res = mysql_perform_query(conn, "show tables");  printf("MySQL Tables in mysql database:\n");
  while ((row = mysql_fetch_row(res)) !=NULL)
  printf("%s\n", row[0]);  /* clean up the database result set */
  mysql_free_result(res);
  /* clean up the database link */
  mysql_close(conn);  return 0;
}当我编译的时候出现如下错误,
\include\mysql_com.h|268|error: expected specifier-qualifier-list before 'SOCKET'|
\include\mysql_com.h|437|error: expected ')' before 's'|在网上看到一个帖子说是缺少“__LCC__”这个定义变量,可以在程序中自己定义,或者加载“winsock.h”库文件或"windows.h"库文件。我都试过,没有成功。。
帖子∶http://www.huomo.cn/database/article-ce00.html求高手帮忙