Hello. I recently moved my help files over to a mysql database. I'm also
going to be moving other parts of my program over to use the database, as
well. That's why I have the open/close function so I don't have to repeat
those lines of code over and over again.

Here's what I have for my common open/closing of a database:

bool open_close_db( MYSQL MySQLConn, bool open ) {
 if (open) {
  if (!mysql_init(&MySQLConn)) {
   logf("For some reason, open_close_db couldn't init a mysql connection.
exitting (BEAUTIFYME)");
   return FALSE;
  }
  if ((mysql_real_connect(&MySQLConn, MY_SERVER, MY_USER, MY_PWD, MY_DB, 0,
NULL, 0)) == NULL) {
   logf("open_close_db died connecting to the mysql server");
   mysql_close(&MySQLConn);
   return FALSE;
  }
 }
 else
  mysql_close(&MySQLConn);
 return TRUE;
}

And here are the first few lines of my do_help function which returns the
help entry entered by the user:
void do_help(CHAR_DATA * ch, char *argument) {
 BUFFER *  output;
 char   argone[MIL];
 char   cleaned[MIL*2];
 int    records;
 char   sql[MSL*2];
 MYSQL   MySQLHelpConn;
 MYSQL_RES * result;
 MYSQL_ROW  row;

 if (argument[0] == '\0') argument = "summary";

 if (!open_close_db( MySQLHelpConn, TRUE ) ) {
  send_to_char( "ERROR: Could not open the database for opening. Please
contact an Imm.\n\r", ch );
  return;
 }

 output = new_buf();
 result = NULL;
 mysql_escape_string(cleaned, argument, strlen(argument));
 while ( argument[0] != '\0' ) {
  argument = one_argument( argument, argone );

  sprintf(sql, "SELECT level, keyword, htext FROM helps WHERE keyword LIKE
'%%%s%%' AND level <= %d", argone, ch->level);
  if (mysql_real_query(&MySQLHelpConn, sql, strlen(sql)) != 0)  {
   logf("do_help died attempting query for %s", argone);
   send_to_char( "Error while getting a query from the database. Please
inform an Imm.\n\r", ch );
   mysql_close(&MySQLHelpConn);
   return;
  }


The problem with this, is that the if statement I have here, returns -1 as
it's value. I don't know what I'm doing wrong here. I've also tried putting
mysql_init( &MySQLHelpConn ); b4 the open_close_db function call. That
didn't help. Any suggestions would be appreciated for this.

Yep, me again,
Rheede :p



Reply via email to