我用mysql_num_rows这个函数总是0mysql_num_rows总是返回0
返回这是我的代码:
#include <mysql/mysql.h>
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
conn = mysql_init(NULL);
if (!mysql_real_connect(conn, "", "", "", "", 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
if (mysql_query(conn, "SELECT * FROM TEST"))
{
printf("MySQL query error : %s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
printf("Rows: %d\n", mysql_num_rows(res));
while ((row = mysql_fetch_row(res)) != NULL)
printf("Row1: %s | Row2: %s | Row3: %s \n", row[0], row[1], row[2]);
mysql_free_result(res);
mysql_close(conn);
而且这是输出
Rows: 0
Row1: 1 | Row2: 127.0.0.1 | Row3: Raspberry
Row1: 2 | Row2: 127.0.0.1 | Row3: Raspberry
MySQL客户端版本:5.5 .44