Write a C/C++ program that connects to a MySQL server and
checks intrusion attempts every 5 minutes. If an intrusion
attempt is detected beep the internal speaker to alert the
administrator. A high number of aborted connects to MySQL at
a point in time may be used as a basis of an intrusion.



Write a C/C++ program that connects to a MySQL server and checks intrusion attempts every 5 minutes..

Answer / ruth

/* Simple C program that connects to MySQL Database server*/
#include <mysql.h>
#include <stdio.h>

main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;

char *server = "localhost";
char *user = "root";
char *password = "PASSWORD"; /* set me first */
char *database = "mysql";

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]);

/* close connection */
mysql_free_result(res);
mysql_close(conn);
}

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Interview Questions

print the palindrome numbers in between 0 to n

1 Answers  


Write a progarm to find the length of string using switch case?

0 Answers   TCS,


What is && in c programming?

0 Answers  


How do you prevent buffer overflows in C?

2 Answers  


How to establish connection with oracle database software from c language?

0 Answers  


Describe the order of precedence with regards to operators in C.

0 Answers  


Diff between for loop and while loop?

2 Answers   TCS,


printf(), scanf() these are a) library functions b) userdefined functions c) system functions d) they are not functions

0 Answers  


Why pointers are used?

0 Answers  


State the difference between x3 and x[3].

0 Answers   Aricent,


Write the program for displaying the ten most frequent words in a file such that your program should be efficient in all complexity measures.

3 Answers   Google,


What has to put when we are inserting as assembly language code into the C code? or When we are inserting as assembly language code into the C code we have to insert one thing at the start and of the assembly language. What are they?

2 Answers  


Categories