//execution :
//./testsqlc
-
-int main(void) {
- MYSQL *conn;
- MYSQL_RES *res;
- MYSQL_ROW row;
- MYSQL_RES *result;
-
- char *server = "";
- char *user = "";
- char *password = "";
- char *database = "";
-
- conn = mysql_init(NULL);
-
- /* Connect to database */
- if (!mysql_real_connect(conn, server,
- user, password, database, 0, NULL, 0)) {
- fprintf(stderr, "%s\n", mysql_error(conn));
- exit(1);
- }
-
- /* send SQL query */
- if (mysql_query(conn, "show tables")) {
- fprintf(stderr, "%s\n", mysql_error(conn));
- exit(1);
- }
-
- res = mysql_use_result(conn);
-
- /* output table name */
- printf("MySQL Tables in mysql database:\n");
- while ((row = mysql_fetch_row(res)) != NULL)
- printf("%s \n", row[0]);
-
- /* query */
- if (mysql_query(conn, "SELECT * FROM Usine"))
- {
- fprintf(stderr, "%s\n", mysql_error(conn));
- exit(1);
- }
-
- result = mysql_store_result(conn);
-
- if (result == NULL)
- {
- fprintf(stderr, "%s\n", mysql_error(conn));
- exit(1);
- }
-
- int num_fields = mysql_num_fields(result);
- int i;
-
- printf("\nTable Usine :\n");
- printf("NU\tNomU\tVille\n");
-
- while ((row = mysql_fetch_row(result)))
- {
- for(i = 0; i < num_fields; i++)
- {
- printf("%s\t", row[i] ? row[i] : "NULL");
- }
- printf("\n");
- }
-
- /* close connection */
- mysql_free_result(res);
- mysql_close(conn);
-
- return 0;
+int main(void)
+{
+ MYSQL *conn;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ MYSQL_RES *result;
+
+ char *server = "";
+ char *user = "";
+ char *password = "";
+ char *database = "";
+
+ conn = mysql_init(NULL);
+
+ /* Connect to database */
+ if (!mysql_real_connect(conn, server,
+ user, password, database, 0, NULL, 0)) {
+ fprintf(stderr, "%s\n", mysql_error(conn));
+ exit(1);
+ }
+
+ /* send SQL query */
+ if (mysql_query(conn, "show tables")) {
+ fprintf(stderr, "%s\n", mysql_error(conn));
+ exit(1);
+ }
+
+ res = mysql_use_result(conn);
+
+ /* output table name */
+ printf("MySQL Tables in mysql database:\n");
+ while ((row = mysql_fetch_row(res)) != NULL)
+ printf("%s \n", row[0]);
+
+ /* query */
+ if (mysql_query(conn, "SELECT * FROM Usine")) {
+ fprintf(stderr, "%s\n", mysql_error(conn));
+ exit(1);
+ }
+
+ result = mysql_store_result(conn);
+
+ if (result == NULL) {
+ fprintf(stderr, "%s\n", mysql_error(conn));
+ exit(1);
+ }
+
+ int num_fields = mysql_num_fields(result);
+ int i;
+
+ printf("\nTable Usine :\n");
+ printf("NU\tNomU\tVille\n");
+
+ while ((row = mysql_fetch_row(result))) {
+ for (i = 0; i < num_fields; i++) {
+ printf("%s\t", row[i] ? row[i] : "NULL");
+ }
+ printf("\n");
+ }
+
+ /* close connection */
+ mysql_free_result(res);
+ mysql_close(conn);
+
+ return 0;
}
-