Listar conteúdo com C e Mysql
#include <mysql/mysql.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	MYSQL *conn;
     	MYSQL_RES *resultado;
     	MYSQL_ROW linha;
     	char *server = "localhost";
     	char *user = "usuario";
     	char *password = "senha"; 
     	char *database = "banco_de_dados";
     	char campo_busca[30], sqlquery[255];
     	conn = mysql_init(NULL);
     	if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
        		fprintf(stderr, "%s\n", mysql_error(conn));
        		exit(1);
    	}
    	printf("Entre com a busca: ");
    	scanf("%s", campo_busca);
	strcpy(sqlquery,"SELECT campo1 FROM tabela where campo_pesquisado like  '%");
	strcat(sqlquery, campo_busca);
	strcat(sqlquery,"%'");
 	if (mysql_query(conn, sqlquery) != 0)                  
  	{                                                                                                  
    	fprintf(stderr, "Não encontrado nenhum item com esse termo \n");                                                              
        exit(1);                                                                      
  	}   
	printf("Encontrada entradas no banco de dados:\n"); 
   	resultado = mysql_use_result(conn);
    	while ((linha = mysql_fetch_row(resultado)) != NULL)
	{
        printf("Valor: : %s \n", linha[0]);

	}
    	mysql_free_result(resultado);
    	mysql_close(conn);
}

Instalando biblioteca necessária no Ubuntu

sudo apt-get install libmysqlclient-dev 

Compilando:

gcc mysql2.c -lmysqlclient -o ex-mysql2
Este artigo foi útil ?
SimNão

12 Replies to “Conexao mysql com C”

  1. 639jili disse:

    Alright, alright, alright. 639jili’s got some sweet promotions goin’ on right now. Just snagged a bonus, feeling lucky! Give ‘em a whirl: 639jili

  2. 123win44 disse:

    123win44, huh? I was kinda skeptical at first, but it’s not bad! Fast payouts, which is a big deal for me. Give it a spin, maybe? 123win44

  3. Saw a Meritbetreklam ad the other day and decided to check it out. Decent bonuses, I think. Should probably look into it more later. If you’re keen, investigate yourself here: meritbetreklam

  4. wplaycasino disse:

    Hmm, wplaycasino… Let’s see. Looks promising, could be a good shout. Give it a try, why not? It’s here wplaycasino.

  5. agent bong88 disse:

    Yo, looking for a solid agent? Agent Bong88 seems like a good place to start. Check ‘em out for yourself! agent bong88

  6. cassinoonline777 is my new fave spot. The games load quick, which is a big plus. Plus, they’ve got a decent variety. Might just stick around for a while. Get in on the action cassinoonline777.

  7. bd3999bed disse:

    I’ve tried a lot of sites but this one stands out for its transparency and speed. Everything is handled professionally at bd3999bed.

  8. kr500casino disse:

    Best casino experience I’ve had in a while. The variety of games is insane and the customer support is very responsive. Definitely visit kr500casino for a great time.

  9. darazplay disse:

    [273]darazplay login করুন এবং রিয়েল মানি স্লট গেম খেলুন,darazplay app download করে বিকাশ পেমেন্ট অনলাইন ক্যাসিনো উপভোগ করুন। ক্যাসিনো বোনাস পাওয়ার নিয়ম জেনে আজই জয়েন করুন। visit: darazplay

  10. vnd188 disse:

    I appreciate how transparent this platform is with their rules. No hidden tricks, just pure fun and fair play. Big thumbs up for vnd188.

  11. ku9iappapk disse:

    Finally found a site that actually works without any glitches. Setting up my account was a breeze and I am already seeing great results with ku9iappapk

  12. I have been playing here for a few weeks now and the payouts are surprisingly fast. Definitely one of the smoothest experiences I have had lately. Check out winpgplataforma for a great time.

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Close Search Window
↑