Error Checking

Hey guys i am facing a problem in my sql statement. I am trying to check if there is such a value in the database.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Code:

  
      string NewMovie = "ww";
  
      string queryText ;
  
   

  queryText = "Select * from movie_info WHERE movie_title = '"+ NewTitle +"'";
      MYSQL *conn;

      conn=mysql_init(NULL);
 
     mysql_real_connect(conn,host,username,password,database,0,NULL,0);
  

  mysql_query(conn,queryText.c_str());
  
       ????
 
      mysql_close(conn);
  
       

      return 0;



The problem i am facing is how do i check if the value is found. I read up and found that a query will return a value of TRUE if the query is a success and a FAIL if there is an error. How do i call these values and then based the check on it?
closed account (S6k9GNh0)
The function probably returns a boolean or integer. Follow the library documentation on how to perform error checking.
This is clearly a question about the MySQL C API (not even the C++ API) and would be best addressed on a MySQL community forum. You are much more likely to get an answer there.
mysql_query() returns an int status code, zero if the command was successful, non-zero for an error code.

1
2
3
4
5
6
7
8
if(mysql_query(/*params*/)){
  //Failed.  
  //Handle errors here
  //Abort query routine here. 
}

//Succeeded.  Process results here


Or alternatively use an else{} instead of some form of aborting, but with complex db interfaces that can result in a lot of nested if/else structures.
Topic archived. No new replies allowed.