Android 第三方框架 相关
2026/5/10 1:57:31
在C语言中进行MySQL编程,主要涉及数据库表的创建、数据插入以及查询结果的获取等操作。
以下是一段示例代码,展示了如何在C语言中删除已存在的students表,创建新的students表,并插入学生记录:
printf("drop students table if exists\n"); if (mysql_query(con, "DROP TABLE IF EXISTS students")) error(); printf("create students tables in cs360\n"); if (mysql_query(con, "CREATE TABLE students(Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name CHAR(20) NOT NULL, score INT)")) error(); printf("insert student records into students table\n"); for (i=0; i<N; i++){ printf("id=%8d name=%10s, score=%4d\n",id[i],name[i],score[i]); sprintf(buf, "INSERT INTO students VALUES (%d, '%s', %d);", id[i], name[i], score[i])