Jump to content
Fórum Script Brasil
  • 0

[Dúvida] MySQL em C++


#VictorMartins

Question

Olá gente, estou aprendendo a usar mysql em C++, e quero que alguém me diga como conecto á alguma tabela? eu só consigo conectar ao banco de dados, código:

#include <windows.h>
#include <iostream>
#include <mysql/mysql.h> 
using namespace std;
int main()
{
//connection params
char *host = "127.0.0.1";
char *user = "root";
char *pass = "Não tem necessidade de informar.";
char *db = "mysql";

//sock
MYSQL *sock;
sock = mysql_init(0);
if (sock) cout << "sock handle ok!" << endl;
else {
cout << "sock handle failed!" << mysql_error(sock) << endl;
}

//connection
if (mysql_real_connect(sock, host, user, pass, db, 0, NULL, 0))
cout << "connection ok!" << endl;
else {
cout << "connection fail: " << mysql_error(sock) << endl;
}

//connection character set
cout << "connection character set: " << mysql_character_set_name(sock) << endl;

//wait for posibility to check system/mysql sockets
system("PAUSE");

//closing connection
mysql_close(sock);

return EXIT_SUCCESS;
}

Edited by #VictorMartins
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...