List:MySQL++« Previous MessageNext Message »
From:Mysql Plusplus Date:December 10 2004 7:40am
Subject:C++ program is not retrieving correct records
View as plain text  
Hi All,
 I have a table in my mysql database named A. The table name is employee.
It contains the following records:

+----------+------------------+-----------------------+        
| Name     | Department       |  JobTitile            |
+----------+------------------+-----------------------+
| X        | Finance          | Analyst               |
| Y        | IT               | Developer             |
| Z        | Marketing        | Area Sales Manager    |
+----------+------------------+-----------------------+

When i am running the following module the records are not being retrieved in proper
order.


MYSQL *conn;
                                                                                
int main()
{
                                                                                
        conn = mysql_init(NULL);
        mysql_real_connect(conn,host,username,password,database,0,NULL,0);
                                                                                
        MYSQL_RES *res_set;
        MYSQL_ROW row;
        int i = 0;
                                                                                
        mysql_query(conn,"SELECT * FROM employee");
        res_set = mysql_store_result(conn);
                                                                                
        while((row = mysql_fetch_row(res_set)) != NULL)
        {
                printf("%s\n",row[i]);
                i++;
        }                                                                                
                                                                     
                                                                                
        mysql_close(conn);
        return 1;
}

The output of the above program is as follows:
[prompt]$ ./a.out
X
IT
Area Sales Manager

Can anyone help me on this? Why I am getting results like this?


Thread
C++ program is not retrieving correct recordsMysql Plusplus10 Dec
  • Re: C++ program is not retrieving correct recordsWarren Young10 Dec