Advertisement
Guest User

konek db di c++

a guest
Oct 31st, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <mysql/mysql.h>//library mysql nya<img draggable="false" class="emoji" alt="🙂" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f642.svg">
  2.  
  3. using namespace std;
  4.  
  5. static char *host="localhost"; //hostname
  6. static char *user="root"; //username
  7. static char *pass=""; //password
  8. static char *db="mysql"; //database
  9. static int port=0; //port
  10. static char *soket=NULL; //soket
  11. static int flags=0; //flags
  12. MYSQL *konek; //objek konek
  13. static MYSQL *conection; //objek conection
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17. string stats;
  18. konek = mysql_init(NULL);
  19. if(konek == NULL){
  20. cout<<"Error!!\n";
  21. exit(1);
  22. }
  23. conection = mysql_real_connect(konek,host,user,pass,db,port,soket,flags);
  24. //mysql_real_connect => buat koneksi ke database mysql + select database yang mau kita gunakan
  25. if(conection==NULL){ //untuk mengecek koneksi, apakah terkoneksi apa tidak
  26. stats="Koneksi tidak ada";
  27. }else{
  28. stats="Anda terkoneksi";
  29. }
  30. cout<<"Status: "<<stats<<endl<<endl;
  31.  
  32. system("PAUSE");
  33. mysql_close(konek);
  34. return EXIT_SUCCESS;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement