List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:May 14 2003 6:45pm
Subject:RE: HELP - C API Problem.
View as plain text  
At 9:43 -0600 5/14/03, Chad Sollis wrote:
>Tried.  And now I get an internal Server error.  Here is the code
>revised.

At what point does the error occur?  Please try to provide more specific
information.

Also note that mysql_query() returns 0 for success, non-zero for
failure, not the other way around.

>
>     static MYSQL *conn;
>     char *query; 
>     int i;
>     conn = mysql_init(NULL);
>     if (conn==NULL) {
>         printf("Failed to connect to DB.  Error1: <br>%s",
>mysql_error(conn));
>         exit(1);
>     };
>    
>     if
>(mysql_real_connect(conn,"localhost","user","pass","db_name",0,NULL,0)==
>NULL) {
>         printf("Failed to connect to DB.  Error2: <br>%s",
>mysql_error(conn));
>         exit(1);
>     }
>     MYSQL_RES *res;
>     MYSQL_ROW row;
>   
>     strcpy(query, "SELECT * FROM os_news");
>    
>     if (!mysql_query(conn, query)) {
>         printf("Failed to connect to DB.  Error3: <br>%s\n",
>mysql_error(conn));
>         exit(1);
>     } else {
>         res=mysql_use_result(conn);
>    
>         printf("<TABLE WIDTH=\"160\" BORDER=\"0\" CELLSPACING=\"2\"
>CELLPADDING=\"0\">");
>
>         while ((row = mysql_fetch_row(res))) {
>             printf("\t<TR>\n\t\t<TD>\n");
>             printf("%s", row[0][1]);
>             printf("\t\t</TD>\n\t</TR>\n");
>         };
>    
>    
>         printf("</TABLE>");
>         mysql_free_result(res);
>     }
>      mysql_close(conn); 
>
>Thanks for your help.
>
>
>-----Original Message-----
>From: Marriner, Bruce W. [mailto:BruceM@stripped]
>Sent: Tuesday, May 13, 2003 5:48 PM
>To: Chad Sollis
>Subject: RE: HELP - C API Problem.
>
>
>
>         I'm not completely sure this will help - Because I'm fairly new
>to the C API.  But I do have a working program that runs on Slackware 8.
>Here's the connect code..
>
>--------------------------------------------------------
>  static MYSQL *conn;
>  /* initialize database connection handler */
>  conn = mysql_init(NULL);
>  if (conn==NULL)
>  {
>    error("mysql_init() failed (probably out of memory)\n");
>    clean_exit(1,NULL);
>  }
>  /* connect to server */
>  if (mysql_real_connect(conn, opt_host_name, opt_user_name,opt_password,
>
>        opt_database, opt_port_num, opt_socket_name, opt_flags) == NULL)
>  {
>    error("mysql_real_connect() failed.");
>    clean_exit(1,NULL);
>  }
>--------------------------------------------------------
>
>         The fields for mysql_real_connect are mostly generated from the
>command-line it should look something like this with some data from the
>user.  The only difference I see is the way you are using mysql_init and
>then passing the handler to mysql_real_connect.
>
>         You said you can connect as osi@localhost thought php so I'll
>assume your GRANT/user table is correct. I remember reading about that
>out of sync thing...  Aww.. Yes.. here
>http://www.mysql.com/doc/en/Commands_out_of_sync.html You might read
>that.  Doesn't sound like it applys to you though..  Also look at
>www.kitebird.com - I just learned there's a online PDF chapter on the C
>API for MySQL there.  You might find that handy.

Thread
HELP - C API Problem.Chad Sollis14 May
  • Re: HELP - C API Problem.Ryan R. Tharp14 May
RE: HELP - C API Problem.Chad Sollis14 May
  • RE: HELP - C API Problem.Paul DuBois14 May
RE: HELP - C API Problem.Chad Sollis14 May