Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Talking to MySQL from C




work with libmysqlclient

gcc -o test test.c /usr/local/lib/mysql/libmysqlclient.dylib


Multiple client stations would be able to add records and view records from different Macs, all sharing the one central MySQL server database. Sounds pretty simple, right ?



you have to setup mysql to authorize extern connexions from the clients

but i think it's not the mailing list to post this ?

#include <stdio.h>
#include <stdlib.h>
#include "/usr/local/mysql/include/mysql.h"

#define table "yourtable"
#define host "localhost"
#define user "user"
#define pass "pass"
#define db "database"

int main()
{
  MYSQL mysql;
  MYSQL_RES *res;
  MYSQL_ROW row;

  int i=0;
  char query[50];

/* make connection to the database */
if(!(mysql_connect(&mysql,host,user,pass)))
{
fprintf(stderr,"mysql_connect() Failed: %s\n",mysql_error (&mysql));
exit(1);
}


/* the database we will use */
if(mysql_select_db(&mysql,db))
{
fprintf(stderr,"mysql_select_db() Failed: %s\n", mysql_error (&mysql));
exit(1);
}


/* Setup the query */
sprintf(query,"select * from %s", table);
if(mysql_query(&mysql,query))
{
fprintf(stderr,"mysql_query() Failed: %s\n", mysql_error (&mysql));
exit(1);
}


  /* store the result from our query */
  res = mysql_store_result(&mysql);

  /* fetch each row from our result and print it */
  while((row = mysql_fetch_row(res))) {
    for(i=0;i<mysql_num_fields(res);i++)
      printf("%s\n",row[i]);
  }

  /* clean up */
  mysql_free_result(res);
  mysql_close(&mysql);
}

also http://mysql-cocoa.sourceforge.net/

Best Regards



-----BEGIN PLUMBER CODE BLOCK-----
Version: 1.0
¬ | | > Regards Plumber || GNU Darwin. ¬ \\\ plumber.gnu-darwin.org ¬
¬ | | > OOP --\///\ (0)=(0) Darwin/Power Mac G4.
¬ | | > ( __ò ó__ ) The best for Fede ¬ \\\ federicafontana.it ¬
------END PLUMBER CODE BLOCK------

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GMU/S d+@ s: a- K+++++ PGP++++ K---- dpu s--:-- C++++ C-- B L X U++++
P+++ C--  P! L--- E+++ W+++ P! L--- N+++ o-- K+++++
------END GEEK CODE BLOCK------

Plain, Loving, Useful, Mischievous, Brutal, Explosive, Responsible

I"It's making my eyes better. And it's legal. I could walk up to the President and blow smoke in his stupid monkey face, and he'd just have to sit there groovin' on it!" Homer J Simpson, Springfield, Illinois, Massachusetts nobody knows :)

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >Talking to MySQL from C (From: Mark Gilbert <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.