Write a C/C++ program to add a user to MySQL.

The user should be permitted to only "SELECT" entries from the given database.
What resources did you use to do research for this project?
What development tools did you do use to complete the project?
How did you test & debug the project?
Why have you chosen to use the programming language used in the project?

Questions by purushottam77

Showing Answers 1 - 2 of 2 Answers

vishnu raju

  • Mar 13th, 2012
 

Try this :)

Code
  1. #include <mysql.h>

  2. #include <stdio.h>

  3. #include <string.h>

  4. #include <stdlib.h>

  5. """";

  6.  

  7. // initialize the variables within

  8. //MYSQL is structure represents a handle to one database connection

  9.  

  10.  

  11. // connect to the database

  12. "localhost","root","mysql","clanguage""in the if block""Conection error : %s

  13. ", mysql_error(connection));            //For print error if connection is not stablished

  14. "connection established successfully

  15. ");

  16.  

  17. //retrieve User name from STDIN

  18. "Enter the User Name

  19. ""%s",name);

  20.  

  21. //retrieve Password from STDIN

  22. "Enter the Password

  23. ""%s",password);

  24.  

  25. //retrieve database name from STDIN

  26. "Enter the Database Name

  27. ""%s",database);

  28.  

  29. //creating SQL query in the form String

  30. "create user ""@localhost identified by """);

  31. //execute the SQL query {create user <user name>@localhost identified by <password>}

  32.         mysql_query(connection,addUser);

  33. //puts(addUser);

  34.  

  35.  

  36. //creating another SQL query in the String

  37. "grant SELECT on "".* to ""@localhost");

  38. //execute the SQL query { grant SELECT on <database name>.* to <user name>@localhost }

  39.         mysql_query(connection,grantACC);

  40. //puts(grantACC);

  41.  

  42.  

  43. //closing the connection

  44. "User has been created Successfully

  45. ");

  46.  

  47. }

Dude, i tried to execute it . it execute successfully . but the grantACC is not getting executed . after adding user and trying to login him , it is saying error 1045(28000)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions