"MYSQL_ROW行"数据类型 [英] "MYSQL_ROW row" Data Type

查看:1051
本文介绍了"MYSQL_ROW行"数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不起作用的原因是MYSQL_ROW行和1或0的整数不是同一数据类型.我如何使它们具有相同的数据类型?

The reason this is not working is that MYSQL_ROW row and an integer of 1 or 0 are not of the same data type. How would i make them the same data type?

           mysql_query(conn,"SELECT COUNT(*) FROM tblURL WHERE IP = ''192.168.1.399'' AND Status = ''Active''");
   my_ulonglong i = 0;
   res_set = mysql_store_result(conn);
   my_ulonglong numrows = mysql_num_rows(res_set);

   {
   row = mysql_fetch_row(res_set);
   if (row[i] = 1) //////THIS IS THE ISSUE??????/////////
       printf("YES: %s\n",row[i]);
   else
       printf("NO: %s\n",row[i]);
   }

   mysql_free_result(res_set);
   mysql_close(conn);
   system("PAUSE");
   /*End Works*/
}

推荐答案

看看文档 ^ ],它解释了MySQL函数返回的数据类型. mysql_fetch_row()返回不是整数值的数据库行.
Take a look at the documentation here[^], which explains the data types returned by MySQL functions. mysql_fetch_row() returns a database row not an integral value.


首先......

在if语句中:
first off...

in an if statement:
if(x = 1)  //<-- this sets x to 1, not compares
if(x == 1) //<-- this compares



第二(假设您的其余代码是洁净的,我假装是)...

您必须查看从MYSQL_ROW进行类型定义的内容,如果它是一个int类型,则比较器应该可以工作,但是如果您需要对其进行强制类型转换,则需要进行显式强制类型转换(通常,如果必须这样做,则应该知道您在执行数据类型方面的操作,可能会导致崩溃,错误或数据丢失):



second (assuming the rest of your code is kosher, i''m pretending it is)...

you have to look up what MYSQL_ROW is typedef''ed from, if its an int, then a comparator should work, but if you need to cast it, you need to do an explicit cast (usually if you have to do this you should know what you''re doing as far as data types, could lead to crashes, bugs, or loss of data):

MYSQL_ROW row;
int x= (int) row; //<-- again this sets it equal to

//In a statement
if(x == row) //<--this compares, but if they''re compatible types the compiler should be ok with it
if(x == (int)row) //<--comparator with explicit cast


我会为您提供更多有关SQL部分的帮助,但是距我上次执行SQL已有数年了.

*****更新:*****


I''d help you more with the SQL portion of it but its been years since I last did SQL.

*****Update:*****

int value; //<--single integer value
int row[10]; //<-- array of 10 integers

if(row == 1) //<-- comparing pointer of array to one (this will likely never be one)
if(row[2] == 1) //<-- comparing third element to one (array indexing starts at zero)


这篇关于"MYSQL_ROW行"数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆