- 论坛徽章:
- 0
|
我是楼主
- #include <stdio.h>
- #include <mysql.h>
- int main()
- {
- MYSQL_RES *result;
- MYSQL_ROW row;
- MYSQL *connection,mysql;
- int state;
- /*连接MYSQL*/
- mysql_init(&mysql);
- connection = mysql_real_connect(&mysql,"127.0.0.0","root","157525","example",0,0,0);
- /*检查连接错误*/
- if(connection==NULL)
- {
- printf(mysql_error(&mysql));
- return -1;
- }
- state = mysql_query(connection,"select * from phone");
- if(state !=0)
- {
- printf(mysql_error(connection));
- return -1;
- }
- /*开存储空间*/
- result = mysql_store_result(connection);
- printf("roes: %d\n",mysql_num_rows(result));
- while((row = mysql_fetch_row(result)) !=NULL)
- {
- printf("id: %s ,val : %s\n",row[0]?row[0]:"NULL",row[1]?row[1]:"NULL");
- }
- mysql_free_result(result);
- mysql_close(connection);
- printf("ok,done\n");
- }
-
-
-
复制代码
[ 本帖最后由 wanghi 于 2006-8-3 18:24 编辑 ] |
|