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
Last modified: 1 de outubro de 2019
Alright, alright, alright. 639jili’s got some sweet promotions goin’ on right now. Just snagged a bonus, feeling lucky! Give ‘em a whirl: 639jili
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
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
Hmm, wplaycasino… Let’s see. Looks promising, could be a good shout. Give it a try, why not? It’s here wplaycasino.
Yo, looking for a solid agent? Agent Bong88 seems like a good place to start. Check ‘em out for yourself! agent bong88
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.