This feature is asked for by many users, but until it is done, this program can be used instead. it is a small program, which also demonstrates few MySQL++ features. #include <sqlplus.hh> 
#define MY_DATABASE     "telcent" 
#define MY_TABLE                "nazivi" 
#define MY_HOST    "localhost" 
#define MY_USER    "root" 
#define MY_PASSWORD "" 
#define MY_FIELD    "naziv" 
#define MY_QUERY    "SELECT URL from my_table as t1, my_table as t2 where t1.field = t2.field" 
int  main (void) { 
  Connection con(use_exceptions); 
        try { 
                ostrstream strbuf; unsigned int i=0; 
                con.real_connect (MY_DATABASE,MY_HOST,MY_USER,MY_PASSWORD,3306,(int)0,60,NULL); 
                Query query = con.query(); query << MY_QUERY; 
                ResUse res = query.use(); Row row; 
                strbuf << "delete from " << MY_TABLE << " where " << MY_FIELD << " in ("; 
//  for UPDATE just replace the above DELETE FROM with UPDATE statement 
                for(;row=res.fetch_row();i++) strbuf <<  row[0] << ","; if (!i) return 0; 
                string output(strbuf.str()); output.erase(output.size()-1,1); output += ")"; 
                query.exec((const string&)output); // cout << output << endl; 
                return 0; 
        } catch (BadQuery er) { 
    cerr << "Error: " << er.error << " " << con.errnum() << endl; 
    return -1; 
        } 

解决方案 »

  1.   

    这里有个C的,你可能需要该一下。这段本来用在cgi里的,我懒的改了。
    #include <stdio.h>
    #include <stdlib.h>
    #include <string>
    #include <iostream>
    #include <lcnet.h>
    #include <mysql.h>using namespace std;int main()
    {
    // crando variables globales
    MYSQL coneccion;
    // construyendo pagina
    cout << "Content-type: text/html\n\n";
    cout << "<html>" << endl;
    // inicializando y conectando 
    if ( mysql_init(&coneccion) == NULL) 
    cout << "error inicializando" << endl;
    if ( mysql_real_connect(&coneccion,"localhost","USUARIO","PASSWORD","mibase",0,NULL,0) == NULL )cout << "error conectando" <<endl;// construyendo insert query char q[200], nombre[30];strcpy(nombre, getstring("NOMBRE").c_str() );strcpy(q,"INSERT INTO mitabla (nombre,edad,estatura) VALUES ( \"" );strcat(q,nombre);strcat(q," \", ");char temp[20];strcpy(temp, getstring("EDAD").c_str() );strcat(q,temp);strcat(q,",");strcpy(temp, getstring("ESTATURA").c_str() );strcat(q,temp);strcat(q,") ");cout << q << endl;if ( mysql_query(&coneccion,q) !=0){cout << "error en insert " <<endl;} else cout << "registro insertado " << endl; mysql_close(&coneccion);cout << "</html>" << endl;exit(0);}
      

  2.   

    上面的那个例子是C++的吧?API不一样,不能用
    我现在用的是MySql4.0
      

  3.   

    int mysql_real_query(MYSQL *mysql, const char *query, unsigned long length) ;
    int mysql_query(MYSQL *mysql, const char *query) ;把你想要的操作(查询,删除,修改,添加……)写成相应的sql语句就可以了。
      

  4.   

    mysql_real_query
    mysqlquery两个函数都可以。