#include #include #include using std::string; using std::cout; using std::endl; const string dh("localhost"); const string du("root"); const string dp(""); const string dd("test"); int main() { MYSQL *m= mysql_init( NULL ); mysql_real_connect(m,dh.c_str(),du.c_str(),dp.c_str(),dd.c_str(),0,NULL,0); string sql("SELECT ? + 1"); MYSQL_STMT *s; MYSQL_BIND bs[1], br[1]; char sparm[50]; unsigned long ulparm, sparml, ulres, ulresl; my_bool isnullp= 0, isnullr; // BIND PARAMETERS FOR QUERY bs[0].buffer_type= MYSQL_TYPE_LONG; bs[0].buffer= (char *)&ulparm; bs[0].is_null= &isnullp; ulparm= 100; isnullp= 0; // BIND RESULTS FOR QUERY br[0].buffer_type= MYSQL_TYPE_LONG; br[0].buffer= (char *)&ulres; br[0].is_null= &isnullr; br[0].length= &ulresl; s= mysql_stmt_init(m); mysql_stmt_prepare(s, sql.c_str(), sql.size()); mysql_stmt_bind_param(s,bs); mysql_stmt_execute(s); mysql_stmt_bind_result(s,br); mysql_stmt_store_result(s); cout << "Result For: " << sql << endl; while (!mysql_stmt_fetch(s)) { cout << "Param: " << ulparm << " NULL: " << (isnullp == 1) << endl; cout << "Value: " << ulres << " NULL: " << (isnullr == 1) << endl; } mysql_stmt_close(s); mysql_close(m); }