title: use C++ with MySql : segmentation fault
body: <p>i'm trying to make a c++ work with MySql 
  i have tested the following code from the link</p>
  
  <p><a href="https://www.raspberrypi.org/forums/viewtopic.php?t=31394&amp;p=272288" rel="nofollow">https://www.raspberrypi.org/forums/viewtopic.php?t=31394&amp;p=272288</a></p>
  
  <pre><code>    #include &lt;iostream&gt;
  #include &lt;mysql/mysql.h&gt; // I added include /usr/include/mysql/ to ld.so.conf which is why that works
  
  using namespace std;
  
  MYSQL *connection, mysql;
  MYSQL_RES *result;
  MYSQL_ROW row;
  int query_state;
  
  #define HOST "localhost" // you must keep the quotes on all four items,  
  #define USER "root" // the function "mysql_real_connect" is looking for a char datatype,
  #define PASSWD "123" // without the quotes they're just an int.
  #define DB "temps"
  
  int main()
  {
  //initialize database connection
      mysql_init(&amp;mysql);
  
  // the three zeros are: Which port to connect to, which socket to connect to 
  // and what client flags to use.  unless you're changing the defaults you only need to put 0 here
      connection = mysql_real_connect(&amp;mysql,HOST,USER,PASSWD,DB,0,0,0); 
  // Report error if failed to connect to database
      if (connection == NULL) {
          cout &lt;&lt; mysql_error(&amp;mysql) &lt;&lt; endl;
          return 1;
      }
  //Send query to database
          query_state = mysql_query(connection, "select * from temps");
  // store result
          result = mysql_store_result(connection);
         while ( ( row = mysql_fetch_row(result)) != NULL ) {
  // Print result, it prints row[column_number])
          cout &lt;&lt; row[0] &lt;&lt; "\t" &lt;&lt; row[1] &lt;&lt; endl;
          }
      return 0;
  }
  </code></pre>
  
  <p>the file compiled successfully with : </p>
  
  <blockquote>
    <p>g++ -o sqlOut -lmysqlclient sqlTest.cpp</p>
  </blockquote>
  
  <p>but i got the error :
   <strong>segmentation fault</strong> when trying to run the compiled file !!!<br>
  any help will be appreciated , thanks </p>
  
  <p>NB : i need to save data from my c++ file into MySql database and view it with phpMyAdmin , it will be very helpfull if you give me another link aor turtorial to foollow </p>
  
  <p>i'm using raspberry pi b+</p>