如何使用未在数据库中定义的变量创建mysql_query

时间:2012-11-13 14:08:27

标签: mysql

我有一个正在进行mysql查询的C代码。但现在我想更新程序中的一个特定列,我无法做到。任何人都可以帮助我。

conn = mysql_init(NULL);   // MySQL Database connection //
mysql_real_connect(conn, NULL, NULL, NULL, "bypass_new", 0, NULL, 0);
mysql_query(conn, "SELECT txnum, rxnum from data");
result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
k = 0;      

while ((row = mysql_fetch_row(result)))
{
  if(row[0])(p_info + k)->callingP   = row[0];
  if(row[1])(p_info + k)->calledP    = row[1];
  mysql_query(conn, "update data set flag_imei=1 where txnum=row[0]");
  k++;
 }

1 个答案:

答案 0 :(得分:1)

尝试以下伪代码的想法,它比你提到的更快,更优化:

 k = 0;      
 myIDsArray = array();

 while ((row = mysql_fetch_row(result)))
 {
   if(row[0])(p_info + k)->callingP   = row[0];
   if(row[1])(p_info + k)->calledP    = row[1];

   myIDsArray.addId(row[0]);

   k++;
 }

  myString = [myIDsArray joinByString:","];
  myQuery = "update data set flag_imei=1 where txnum in ( " . myString . " ) ";
  mysql_query(conn, myQuery);