C++ 连接 mariadb

#include 
#include 
#include 
#include 

void show_error(MYSQL *mysql)
{
  printf("Error(%d) [%s] \"%s\"", mysql_errno(mysql),
                                  mysql_sqlstate(mysql),
                                  mysql_error(mysql));
  mysql_close(mysql);
  exit(-1);
}

int main(int argc, char *argv[])
{
  MYSQL *mysql;
  const char *query;
  MYSQL_RES *result;

  mysql= mysql_init(NULL);
  if (!mysql_real_connect(mysql, "localhost", "root", "412413", 
                          "test", 0, "/var/lib/mysql/mysql.sock", 0))
    show_error(mysql);

 
 query= "INSERT INTO test (id,name,age,seq) VALUES (\"k1507072\", \"Gary\",31,1)";
         
  if (mysql_real_query(mysql, query, strlen(query)))
    show_error(mysql);



  mysql_close(mysql);
  return 0;
}

你可能感兴趣的:(c/c++)