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.
Answer Posted / raghavendra
/* 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 ? | 17 Yes | 11 No |
Post New Answer View All Answers
Why should I use standard library functions instead of writing my own?
what are the facialities provided by you after the selection of the student.
What is use of null pointer in c?
Why c is called a middle level language?
Where is c used?
Why does everyone say not to use scanf? What should I use instead?
What does sizeof return c?
Tell me can the size of an array be declared at runtime?
What are pragmas and what are they good for?
Is it better to use a macro or a function?
Write a program to find factorial of a number using recursive function.
What is pass by reference in functions?
What is difference between structure and union in c?
What are global variables?
What is header file definition?