- 论坛徽章:
- 0
|
这是抄来的一段代码,编译通过,有个地方看不懂,所以请教大家,源码舅下
[root@localhost c]# cat test.c
- #include <sys/time.h>;
- #include <stdio.h>;
- #include <mysql.h>;
- int main (char **args)
- {
- MYSQL_RES *result;
- MYSQL_ROW row;
- MYSQL *connection, mysql;
- int state;
- /* connect to database */
- mysql_init(&mysql);
- connection = mysql_real_connect(&mysql,"192.168.3.113","root","654321","bm",0,0,0);
- /* check for connection error */
- if (connection == NULL)
- {
- /* print error message */
- printf(mysql_error(&mysql));
- return 1;
- }
- state = mysql_query(connection, "SELECT sn, id FROM account");
- if (state != 0)
- {
- printf(mysql_error(connection));
- return 1;
- }
- /* must call mysql_store_result() before we can issue any other
- * * query calls
- * */
- result = mysql_store_result(connection);
- printf("Rows: %dn", mysql_num_rows(result));
- /* process each row in result set */
- while ((row = mysql_fetch_row(result)) != NULL)
- {
- printf("id: %s, val: %sn",
- (row[1] ? row[1] : "NULL"),
- (row[0] ? row[0] : "NULL"));
- }
- /* free the result set */
- mysql_free_result(result);
- /* close the connection */
- mysql_close(connection);
- printf("Done.n");
- }
复制代码
下面这一段我就看不懂了,(row[1] ? row[1] : "NULL" ,是怎么得也来的,还有就是我如果需要把这些值拿出来做计算,那是不是要重新定义变量呢,谢谢
while ((row = mysql_fetch_row(result)) != NULL)
{
printf("id: %s, val: %sn",
(row[1] ? row[1] : "NULL" ,
(row[0] ? row[0] : "NULL" ); |
|