mercredi 6 mai 2020

i can not retrieve the data from mysql database using c++

hey i'm a newbie in c++, i got thise error in mycode, Error: invalid operands of types ‘const char [35]’ and ‘const char [2]’ to binary ‘operator+’ and i stuck at those cases, and this my code

#include <iostream>
#include <bits/stdc++.h>
#include <windows.h>
#include <mysql.h> //header mysql
#include <sstream>  //merubah semua tipe data yang diinputkan user ke string
#include <algorithm> //untuk menggunakan fungsi begin, end
#include <regex>

using namespace std;

int main()
{
string hadis;
MYSQL* conn; //for connection handler
MYSQL_ROW row, row1; // return data as array of strings
MYSQL_RES* res; //hold the result set
int num_fields;
conn = mysql_init(0); //initialaize connection handler. dont change!
conn = mysql_real_connect(conn, "192.168.43.205", "ibrahim", "hadis", "hadis", 0, NULL, 0);
if(conn)
{
    int qstate = mysql_query(conn, "SELECT Isi_Indonesia FROM malik");
    if(!qstate)
    {
    res = mysql_store_result(conn); //
    num_fields = mysql_num_fields(res);
    while(row = mysql_fetch_row(res)) //mysqli fetch srray, Fetch all rows from the result
      {
      data = row[0];
      regex reg("[^\\w]+");
      data = regex_replace(data, reg, " ");
      //cout << data <<"\n\n";
      istringstream stm(data) ;
      while( stm >> hadis ) // read white-space delimited tokens one by one
       {
       for(int i = 0; i < num_fields; i++)
       {
       const char *hadiss = hadis.c_str();
       if(hadiss != NULL)
       {
       cout << hadiss << endl;
   /* 1st error */    mysql_query(conn,"SELECT kata FROM totalkata_malik2 WHERE kata='"+hadiss+"'"); //the 1st error
       res = mysql_store_result(conn);
       int num_fields = mysql_num_fields(res);
       while ((row = mysql_fetch_row(res)))
        {
 /* 2nd error */  string query2 = "INSERT INTO totalkata_malik2(kata,total) VALUES ('"+hadiss+"',1)"; // the code that got 2nd error
        mysql_query(conn, query2.c_str());
        }

         }

             else
             cout << "NULL" << endl;

               }
            }

        }
    }
}
return 0;
 }

i've tried to search some references but i cant understand them therefore i dont know what must i do to solve both of errorr

Aucun commentaire:

Enregistrer un commentaire