List:MySQL on Win32« Previous MessageNext Message »
From:Paul DuBois Date:January 30 2000 9:10pm
Subject:Re: Whats wrong with this C++ code? It compiles fine, but doesn't
run.
View as plain text  
You have to call mysql_init() prior to mysql_real_connect().
Since you don't, you're passing garbage as the first argument
to mysql_real_connect().

You also don't check whether or not mysql_real_connect(),
mysql_query(), or mysql_store_result() succeed or fail.
It would be a good idea to add some error checking, or
you're going to make it hard to track down any other problems
you may have.


At 11:17 PM +0300 2000-01-30, Indeyets wrote:
>#include<mysql.h>
>#include<iostream>
>using namespace std;
>
>int main(void)
>{
>         MYSQL *connection;
>         MYSQL_RES *result;
>         MYSQL_ROW row;
>
>         connection = mysql_real_connect(connection, NULL, NULL, 
>NULL, "mysql", 3306, NULL, 0);
>         mysql_query(connection, "select * from user");
>         result = mysql_store_result(connection);
>         while(row = mysql_fetch_row(result))
>         {
>                 cout << row[0];
>         }
>         mysql_close(connection);
>         exit(0);
>}


-- 
Paul DuBois, paul@stripped
Thread
Whats wrong with this C++ code? It compiles fine, but doesn't run.Indeyets30 Jan
  • Re: Whats wrong with this C++ code? It compiles fine, but doesn'trun.Paul DuBois31 Jan
  • Re: Whats wrong with this C++ code? It compiles fine, but doesn't run.sinisa@mysql.com31 Jan