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.

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / jack

#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 ?    5 Yes 11 No

Post New Answer

More C Interview Questions

what is foreign key in c language?

1 Answers   ADP,


the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above

0 Answers  


Explain what is wrong in this statement?

0 Answers  


How can I convert a number to a string?

0 Answers  


how can we use static and extern?and where can we use this?

3 Answers   Excel,






What is break statement?

0 Answers  


write a program to generate 1st n fibonacci prime number

12 Answers  


How the processor registers can be used in C ?

7 Answers   HP,


Explain enumerated types in c language?

0 Answers  


On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area

0 Answers  


What is a file descriptor in c?

0 Answers  


what is the difference between postfix and prefix unary increment operators?

3 Answers  


Categories