欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C語言實(shí)現(xiàn)訪問及查詢MySQL數(shù)據(jù)庫的方法

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

本文實(shí)例講述了C語言實(shí)現(xiàn)訪問及查詢MySQL數(shù)據(jù)庫的方法。分享給大家供大家參考,具體如下:

1、添加頭文件路徑(MySQL安裝路徑中的include路徑)
2、添加庫文件(直接從MySQL安裝路徑中copy libmysql.lib即可)
3、編程操作數(shù)據(jù)庫

代碼

// AccessToMySQL.cpp : 定義控制臺應(yīng)用程序的入口點(diǎn)。
//
#include "stdafx.h"
#include <Windows.h>
#include <mysql.h>
#pragma comment(lib,"libmysql.lib")
MYSQL mysql;
MYSQL_RES* result;
MYSQL_ROW row;
int main(void)
{
  //init the mysql parameter
  mysql_init(&mysql);
  //connect the database
  if(!mysql_real_connect(&mysql,"127.0.0.1","root","111","mytest",3306,NULL,0))
  {
    printf(mysql_error(&mysql));
    printf("\nCannot access to the database!!!\n");
    system("pause");
    exit(-1);
  }
  //construct the query SQL statements
  char* sql="select * from student where name='";
  char dest[100]={""};
  strcat(dest,sql);
  printf("Please enter the student name:");
  char name[10]={""};
  gets(name);
  strcat(dest,name);
  strcat(dest,"'");
  //excute the SQL statements
  if(mysql_query(&mysql,dest))
  {
    printf("Cannot access the database with excuting \"%s\".",dest);
    system("pause");
    exit(-1);
  }
  //deal with the result
  result=mysql_store_result(&mysql);
  if(mysql_num_rows(result))
  {
    while((row=mysql_fetch_row(result)))
    {
      printf("%s\t%s\t%s\n",row[0],row[1],row[2]);
    }
  }
  //release the resource
  mysql_free_result(result);
  mysql_close(&mysql);
  system("pause");
  return 0;
}

運(yùn)行效果:

希望本文所述對大家C語言程序設(shè)計有所幫助。

上一篇:opencv實(shí)現(xiàn)圖片與視頻中人臉檢測功能

欄    目:C語言

下一篇:基于make命令與makefile文件詳解

本文標(biāo)題:C語言實(shí)現(xiàn)訪問及查詢MySQL數(shù)據(jù)庫的方法

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/1000.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有