MYSQL_ROW是什么数据类型_“MYSQL_ROW行”数据类型

bd96500e110b49cbb3cd949968f18be7.png

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*/

}

解决方案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.

first off...

in an if statement:

if(x = 1) //

if(x == 1) //

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; //

//In a statement

if(x == row) //

if(x == (int)row) //

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

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

int value; //

int row[10]; //

if(row == 1) //

if(row[2] == 1) //

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用`MYSQL_ROW`获取查询结果集中的数据,您可以使用索引或字段名称来访问每一列的数据。以下是一个示例: ```cpp #include <mysql/mysql.h> #include <iostream> int main() { // 初始化MySQL连接 MYSQL mysql; mysql_init(&mysql); // 建立与MySQL服务器的连接 if (!mysql_real_connect(&mysql, "localhost", "username", "password", "database", 0, NULL, 0)) { std::cout << "连接到MySQL服务器失败: " << mysql_error(&mysql) << std::endl; return 1; } // 执查询 const char* query = "SELECT * FROM table"; if (mysql_real_query(&mysql, query, strlen(query)) != 0) { std::cout << "查询执失败: " << mysql_error(&mysql) << std::endl; return 1; } // 获取查询结果集 MYSQL_RES* result = mysql_store_result(&mysql); if (result == NULL) { std::cout << "获取查询结果集失败: " << mysql_error(&mysql) << std::endl; return 1; } // 遍历结果集并获取数据 MYSQL_ROW row; while ((row = mysql_fetch_row(result))) { // 获取每一列的数据 // 使用索引获取数据 std::cout << "第一列数据: " << row[0] << std::endl; // 使用字段名称获取数据 std::cout << "字段名称为 'column_name' 的数据: " << mysql_fetch_field(result)->name << std::endl; // 可以根据需要使用其他索引或字段名称获取数据 std::cout << std::endl; } // 释放结果集内存 mysql_free_result(result); // 关闭与MySQL服务器的连接 mysql_close(&mysql); return 0; } ``` 在上述示例中,我们使用了`mysql_fetch_row`函数来遍历结果集中的每一数据,并将每一的数据存储在`MYSQL_ROW`类型的变量`row`中。 然后,我们可以使用索引或字段名称来访问每一列的数据。使用索引时,可以通过`row[i]`来获取第i+1列的数据,索引从0开始。使用字段名称时,可以通过`mysql_fetch_field(result)->name`来获取指定列的字段名称,并通过索引或字段名称来获取相应的数据。 在示例中,我们分别使用索引和字段名称来获取第一列和名为'column_name'的列的数据,并将它们输出到控制台。 请根据您的具体需求和表结构调整代码,并根据需要获取其他列的数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值