Advertisement
Ciro_meneses

Untitled

Oct 24th, 2018
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 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 "root" sem senha "". ele conecta ao database "banco"
  11.     if ( mysql_real_connect(&conexao, "127.0.0.1", "root", "", "meubanco", 0, NULL, 0) )
  12.     {
  13.        printf("\nConexao ao banco realizada com sucesso!\n");
  14.        mysql_query(&conexao,"INSERT INTO PESSOA(nome, sexo) values('Matheus Miranda', 'M');");
  15.         mysql_close(&conexao);
  16.     }
  17.     else
  18.     {
  19.         printf("Falha de conexao\n");
  20.         printf("Erro %d : %s\n", mysql_errno(&conexao), mysql_error(&conexao));
  21.     }
  22.  
  23.     return(0);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement