通过C在MySQL中创建测试数据库

时间:2012-02-19 13:50:38

标签: mysql c

当我尝试编译以下代码时,我收到了编译错误。

#include "my_global.h"
#include "mysql.h"

int main(void)
{
   MYSQL *conn;
   conn = mysql_init(NULL);
   if (conn == NULL) {
         printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
         exit(1);
   }

   if (mysql_real_connect(conn, "localhost", "zetcode",
          "passwd", NULL, 0, NULL, 0) == NULL) {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

  if (mysql_query(conn, "create database testdb")) {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }


  mysql_close(conn);

  return 0;
}

我在Windows 7上使用Borland 32位编译器来编译以下代码。我的编译命令看起来像这样

c:\Borland\BCC55>bcc32 -Ic:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2
-win32-vs2005\include -c creatingTESTDB.c

我收到六个编译错误:

  

Borland C ++ 5.5.1 for Win32版权所有(c)1993,2000 Borland   creatingTESTDB.c:
警告W8017   C:\用户\奥修\桌面\ MySQL的连接器-C-noinstall-6.0.2-Win32的VS20   05 \ include \ config-win.h 111:重新定义'S_IRWXU'不是   相同的

错误E2238   C:\用户\奥修\桌面\ MySQL的连接器-C-noinstall-6.0.2-Win32的VS2005   \ include \ config-win.h 114:'mode_t'的多重声明

  错误E2344 c:\ Borland \ Bcc55 \ include \ sys / types.h 35:早些时候   声明'mod e_t'

错误E2141   C:\用户\奥修\桌面\ MySQL的连接器-C-noinstall-6.0.2-Win32的VS2005   \ include \ config-win.h 265:声明函数中的语法错误   double2ulonglong

错误E2378   C:\用户\奥修\桌面\ MySQL的连接器-C-noinstall-6.0.2-Win32的VS2005   \ include \ config-win.h 268:缺少返回语句;在功能上   double2ulonglo ng

错误E2293   C:\用户\奥修\桌面\ MySQL的连接器-C-noinstall-6.0.2-Win32的VS2005   \ include \ my_global.h 1591 :)预期功能rint

错误   E2293   C:\用户\奥修\桌面\ MySQL的连接器-C-noinstall-6.0.2-Win32的VS2005   \ include \ my_global.h 1595 :)预期功能rint

  编译* * 6错误

非常感谢任何帮助。 我在尝试编译以下代码时遇到编译错误。

#include "my_global.h"
#include "mysql.h"

int main(void)
{
   MYSQL *conn;
   conn = mysql_init(NULL);
   if (conn == NULL) {
         printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
         exit(1);
   }

   if (mysql_real_connect(conn, "localhost", "zetcode",
          "passwd", NULL, 0, NULL, 0) == NULL) {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

  if (mysql_query(conn, "create database testdb")) {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }


  mysql_close(conn);

  return 0;
}

我在Windows 7上使用Borland 32位编译器来编译以下代码。我的编译命令看起来像这样

c:\Borland\BCC55>bcc32 -Ic:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2
-win32-vs2005\include -c creatingTESTDB.c

我收到六个编译错误:

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
creatingTESTDB.c:<br> Warning W8017
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs20
05\include\config-win.h 111: Redefinition of 'S_IRWXU' is not
identical<br><br> Error E2238
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\config-win.h 114: Multiple declaration for 'mode_t'<br><br>
Error E2344 c:\Borland\Bcc55\include\sys/types.h 35: Earlier
declaration of 'mod e_t'<br><br> Error E2141
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\config-win.h 265: Declaration syntax error in function
double2ulonglong<br><br> Error E2378
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\config-win.h 268: Return statement missing ; in function
double2ulonglo ng<br><br> Error E2293
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\my_global.h 1591: ) expected in function rint<br><br> Error
E2293
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\my_global.h 1595: ) expected in function rint<br><br>
*** 6 errors in Compile ***

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

您没有提供您正在使用的MySQL版本。尝试添加以下标题:

#include "my_sys.h"

要查看的其他来源是: