MariaDB社区
标题:
关于c语言中mysql的select语句变量查询问题
[打印本页]
作者:
zlmay007
时间:
2009-4-8 09:46
标题:
关于c语言中mysql的select语句变量查询问题
程序如下:
#include <stdlib.h>
#include <stdio.h>
#include "mysql/mysql.h"
MYSQL my_connection;
MYSQL_RES *res_ptr;
MYSQL_ROW sqlrow;
char *userName="z";//!
void display_row();
int main(int argc, char *argv[]) {
int res;
mysql_init(&my_connection);
if (mysql_real_connect(&my_connection, "localhost", "root",
"111111", "zl", 0, NULL, 0)) {
printf("Connection success\n");
res = mysql_query(&my_connection, "SELECT username,password FROM user where='userName'");//!??
if (res) {
printf("SELECT error: %s\n", mysql_error(&my_connection));
} else {
res_ptr = mysql_use_result(&my_connection);
if (res_ptr) {
while ((sqlrow = mysql_fetch_row(res_ptr))) {
printf("Fetched data...\n");
display_row();
}
if (mysql_errno(&my_connection)) {
printf("Retrive error: %s\n", mysql_error(&my_connection));
}
}
mysql_free_result(res_ptr);
}
mysql_close(&my_connection);
} else {
fprintf(stderr, "Connection failed\n");
if (mysql_errno(&my_connection)) {
fprintf(stderr, "Connection error %d: %s\n",
mysql_errno(&my_connection), mysql_error(&my_connection));
}
}
return EXIT_SUCCESS;
}
void display_row() {
unsigned int field_count;
field_count = 0;
while (field_count < mysql_field_count(&my_connection)) {
printf("%s ", sqlrow[field_count]);
field_count++;
}
printf("\n");
}
运行之后程序说明可以连接成功,但是却无关于z的用户名输出,请问大家这是为什么呢?应该如何修改?
作者:
kider
时间:
2009-4-9 17:09
关注...
作者:
beingman
时间:
2012-6-29 13:31
应该是SQL语句不完整吧,遗漏了字段名:
res = mysql_query(&my_connection, "SELECT username,password FROM user
where='userName'
");//!??
欢迎光临 MariaDB社区 (http://123.56.88.72/)
Powered by Discuz! X3.2