当前位置: 技术问答>linux和unix
C语言操作数据库的一个小问题
来源: 互联网 发布时间:2016-06-23
本文导语: 有以下程序段: MYSQL my_connection; MYSQL_RES *res_ptr; mysql_query(&my_connection,"select * from students where id=55") res_ptr = mysql_store_result(&my_connection); if(res_ptr) { mysql_query(&my_connection, "delete from students where id=55"); ...
有以下程序段:
MYSQL my_connection;
MYSQL_RES *res_ptr;
mysql_query(&my_connection,"select * from students where id=55")
res_ptr = mysql_store_result(&my_connection);
if(res_ptr)
{
mysql_query(&my_connection, "delete from students where id=55");
printf("删除成功!n");
}
else
printf("删除失败!n");
为什么不管我的students表格中是否有id为55的学生,它总是打印出“删除成功!”,也就是mysql_store_result(&my_connection);这句话总为真。这是为什么呢?
MYSQL my_connection;
MYSQL_RES *res_ptr;
mysql_query(&my_connection,"select * from students where id=55")
res_ptr = mysql_store_result(&my_connection);
if(res_ptr)
{
mysql_query(&my_connection, "delete from students where id=55");
printf("删除成功!n");
}
else
printf("删除失败!n");
为什么不管我的students表格中是否有id为55的学生,它总是打印出“删除成功!”,也就是mysql_store_result(&my_connection);这句话总为真。这是为什么呢?
|
对指针的判空请使用
if (NULL != res_ptr)
if (NULL != res_ptr)
|
res_ptr是指针??它为零代表什么?
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。