> Can someone give me a quick *complete* example code of setting up a
> connection, performing a small query, and reading back the result?
>

In windows install, there is an examples directory which contains mytest.c.
I can't say if this exists for Linux but I bet it does in some form.  Why
don't you scan the mysql directory structure and see if you can't find this
(or similar).


>   if(!mysql_real_connect(&mysql, "localhost",
>                          "user", "passwd", "dbname", 0, "", 0))
This is wrong.  You are passing an empty string as the Unix socket.  Try
using NULL instead.

> -----Original Message-----
> From: HaB JacKaL [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, September 20, 2001 9:10 AM
> To: [EMAIL PROTECTED]
> Subject: C API problems
>
>
> Can someone give me a quick *complete* example code of setting up a
> connection, performing a small query, and reading back the result?
>
>
> The docs conflict in a few places as far as how to declare the
> data types.
> (in some places, they are pointers, in others they are not).  Also, the
> examples, sadly, just aren't very good.  And there is no example for
> mysql_use_result().  (the example code uses mysql_store_result())
>
> I have tried every combination of pointers and regular datatypes
> I can think
> of, but I'm still generating errors on compile.
>
> Running on linux (RH 7.1), with MySQL 3.23.39.
>
> I'm using this:
>
>   MYSQL mysql;
>   MYSQL_RES *result;
>   MYSQL_ROW row;
>   int error;
>
>   if(!mysql_init(&mysql))
>     {
>       printf("init failed!\n");
>       exit(1);
>     }
>
>   if(!mysql_real_connect(&mysql, "localhost",
>                          "user", "passwd", "dbname", 0, "", 0))
>     {
>       printf("doh!  connect failed...\n");
>       exit(1);
>     }
>   else
>     {
>       error = mysql_select_db(&mysql, "label");
>       error = mysql_query(&mysql, "SELECT * FROM _countries");
>       result = mysql_use_result(&mysql);
>       while((row = mysql_fetch_row(result)))
>         {
>
> mysql_init() is returning fine...
>
> The connection is failing.  I know the username/password combo
> works, since
> I can use it on the command line.  The client program is being run on the
> same linux machine as the mysql server.
>
> Any other ideas?
>
> Does mysqld have a debug mode?  Some way I can see if the client is even
> trying to connect, and what data the server is getting?
>
> Also, are the datatypes declared correctly for the rest of the code?  The
> docs conflict as to whether or not result should be declared as a
> pointer or
> not.
>
>
> Thanks.
>
> -HaB
>
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to