当前位置: 技术问答>linux和unix
请大家帮忙看看这段代码为什么不行,关于mysql的
来源: 互联网 发布时间:2015-11-26
本文导语: 这是表class中的数据 mysql> select * from class; +--------+--------+--------+---------+--------+ | gender | height | name | home | weight | +--------+--------+--------+---------+--------+ | female | 160 | julie | canca | 100 | | male | 170 | robert ...
这是表class中的数据
mysql> select * from class;
+--------+--------+--------+---------+--------+
| gender | height | name | home | weight |
+--------+--------+--------+---------+--------+
| female | 160 | julie | canca | 100 |
| male | 170 | robert | califor | 120 |
| female | 165 | kate | losan | 90 |
| male | 180 | kim | washi | 130 |
+--------+--------+--------+---------+--------+
4 rows in set (0.01 sec)
mysql> describe class
-> ;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| gender | varchar(20) | YES | | NULL | |
| height | double | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| home | varchar(20) | YES | | NULL | |
| weight | double | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
我想先"select * from class where gender = 'female'",然后找出字段weight中值为100的那一行,
以下是代码:
#include
#include
#include
int main()
{
char sql[20];
MYSQL * mysql;
MYSQL_ROW row;
MYSQL_RES * res;
MYSQL_FIELD * fields;
MYSQL_FIELD_OFFSET offset;
mysql = mysql_init(NULL);
if(!mysql_real_connect(mysql,"localhost","root","dcsec2005","scut",0,NULL,0))
cout
mysql> select * from class;
+--------+--------+--------+---------+--------+
| gender | height | name | home | weight |
+--------+--------+--------+---------+--------+
| female | 160 | julie | canca | 100 |
| male | 170 | robert | califor | 120 |
| female | 165 | kate | losan | 90 |
| male | 180 | kim | washi | 130 |
+--------+--------+--------+---------+--------+
4 rows in set (0.01 sec)
mysql> describe class
-> ;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| gender | varchar(20) | YES | | NULL | |
| height | double | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| home | varchar(20) | YES | | NULL | |
| weight | double | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
我想先"select * from class where gender = 'female'",然后找出字段weight中值为100的那一行,
以下是代码:
#include
#include
#include
int main()
{
char sql[20];
MYSQL * mysql;
MYSQL_ROW row;
MYSQL_RES * res;
MYSQL_FIELD * fields;
MYSQL_FIELD_OFFSET offset;
mysql = mysql_init(NULL);
if(!mysql_real_connect(mysql,"localhost","root","dcsec2005","scut",0,NULL,0))
cout