mysql_real_connect will do a mysql_init if you feed it a null pointer in
place of a MYSQL *.  if you feed it a MYSQL * that you got from mysql_init
it will allow you to retrieve an errors that occur.  that's actually
documented in the MySQL 3.22 documentation...

---
[EMAIL PROTECTED]


On Thu, 14 Jan 1999, Michael A. Smith wrote:

> OK,
> 
> I figured out much of the details of getting things compiled all by myself.
> I do have an API question.
> 
> I've called mysql_init(NULL) to initialize a new MYSQL object.
> mysql_real_connect then uses this to connect to the database.
> 
> I'm confused about the return values of these two functions. I've created a
> pointer to the MYSQL struct named "dbconn". Which of these two functions
> should assign its value to "dbconn"??
> 
> Also, what should the "MYSQL *mysql" argument of the mysql_real_connect be?
> I asumed it's the value of mysql_init. If so, to what is the return value
> of mysql_real_connect assigned (if not "dbconn").
> 
> 
> /* SAMPLE PROGRAM */
> #include <stdio.h>
> #include </usr/local/mysql/include/mysql.h>
> #define HOST "localhost"
> #define USER ""
> #define PASSWORD ""
> #define DB "test"
> #define TABLE "mastest"
> 
> int main() {
>    MYSQL *dbconn;
>    char myquery[] = "insert into TABLE (name) values ('michael')";
>    int res;
> 
>    /* BEGIN MESSED UP PARTS */
>    /* assign dbconn here? */
>    dbconn = mysql_init(NULL);
>    /* or here? */
>    dbconn = mysql_real_connect(?????,HOST,USER,PASSWORD,DB,0,NULL,0);
>    /* END MESSED UP PARTS (hopefully) */
> 
>    res = mysql_query(dbconn, myquery);
>    if (!res) {
>       printf("query successful!\n");
>    } else {
>       printf("query result = %i\n",res);
>    }
>    mysql_close(dbconn);
>    return(0);
> }
> 
> Thanks!!
> ****************
> Michael A. Smith | [EMAIL PROTECTED]
> Site Development Engineer | digitalNATION | http://www.dn.net
> ****************
> "The programmer, like the poet, works only slightly removed from pure
> thought-stuff. He builds his castles in the air, from air, creating by
> exertion of the imagination. Few media of creation are so flexible, so easy
> to polish and rework, so readily capable of realizing grand conceptual
> structures."
>                                     --Frederick P. Brooks, Jr
>                                       The Mythical Man-Month
> ****************
> -----------------------------------------------------------
> Send a mail to [EMAIL PROTECTED] with
> unsubscribe mysql [EMAIL PROTECTED]
> in the body of the message to unsubscribe from this list.
> 

-----------------------------------------------------------
Send a mail to [EMAIL PROTECTED] with
unsubscribe mysql [EMAIL PROTECTED]
in the body of the message to unsubscribe from this list.

Reply via email to