Ciro_meneses

teste mysql server connection

Jun 11th, 2016
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <winsock2.h>
  4. #include <mysql.h>
  5.  
  6.  
  7. int main() {
  8.     MYSQL conexao;
  9.     mysql_init(&conexao);
  10.     // Aqui tenho um servidor mysql rodando no IP: 127.0.0.1 com usuário "dev" sem senha "". ele conecta ao database "test"
  11.     if ( mysql_real_connect(&conexao, "127.0.0.1", "dev", "", "test", 0, NULL, 0) )
  12.     {
  13.        printf("\nConexao ao banco realizada com sucesso!\n");
  14.     }
  15.     else
  16.     {
  17.         printf("Falha de conexao\n");
  18.         printf("Erro %d : %s\n", mysql_errno(&conexao), mysql_error(&conexao));
  19.     }
  20.     system("PAUSE");
  21.     return(0);
  22. }
Add Comment
Please, Sign In to add comment