Home  >  Article  >  Database  >  简单介绍MySQL API编程

简单介绍MySQL API编程

WBOY
WBOYOriginal
2016-06-07 16:04:211134browse

下文代码中的m_ListBox是一个ListBox控件。 MYSQL *myData; MYSQL_RES *myResult; CString str; MYSQL_ROW row; unsigned int num_fields; unsigned int i; unsigned long *lengths; m_ListBox.ResetContent(); ASSERT(m_ListBox.GetCount() == 0); if ( (my

下文代码中的m_ListBox是一个ListBox控件。

<code>MYSQL   *myData;
 MYSQL_RES  *myResult;
 CString   str;
 MYSQL_ROW  row;
 unsigned int num_fields;
 unsigned int i;
 unsigned long *lengths;
 m_ListBox.ResetContent();
 ASSERT(m_ListBox.GetCount() == 0);
 if ( (myData = mysql_init((MYSQL*) 0)) &&
  mysql_real_connect( myData, NULL, "root", NULL, NULL, MYSQL_PORT,
  NULL, 0 ) )//初始化,连接数据库,本地连接,使用root账号,无密码,默认端口
 {
  m_ListBox.AddString("连接成功");
  if (myResult=mysql_list_dbs(myData, "%"))//枚举数据库
  {
   m_ListBox.AddString("枚举数据库成功");
   num_fields=mysql_num_fields(myResult);//获取结果的数据结构数目
   while ((row=mysql_fetch_row(myResult)))//获取下一行数据
   {
    lengths=mysql_fetch_lengths(myResult);
    for(i=0;i<num_fields code mydata mysql_close m_listbox.addstring else mysql_free_result mysql_num_rows str.format : row lengths></num_fields></code>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn