C connection to MySQL database development: Xcode environment configuration and testing _ MySQL

Source: Internet
Author: User
C connection to MySQL database development: Xcode environment configuration and testing I. development environment

Mac OS X 10.9.2 64-bit, Xcode5.1, and MySQL5.5.37 64-bit

MySQL installation directory:/usr/local/mysql

2. configure the compilation options for connecting xcode to mysql

1> add the mysql header file directory to the xcode header file search path.

Project properties --> Build Settings --> Search Paths --> Header Search Paths, add/Usr/local/mysql/include


2> add the mysql library file directory to the xcode library file search path

Project properties --> Build Settings --> Search Paths --> Library Search Paths, add/Usr/local/mysql/lib


3> add link tag options

Project properties --> Build Settings --> Linking --> Other Linker Flags, add the following tag:

-Lmysqlclient

-Lm

-Lz


4> link the mysql dynamic library to the/usr/lib Directory

Ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib


III. test and development environment

//// Main. c // mysql database programming /// Created by YangXin on 14-5-22. // Copyright (c) 2014 yangxin. all rights reserved. // # include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
MYSQL mysql; int main (int argc, const char * argv []) {/* before connection, use mysql_init to initialize the MYSQL connection handle */mysql_init (& mysql ); /* use mysql_real_connect to connect to the server. the parameters are MYSQL handle, server IP address, username and password used to log on to mysql, and the database to be connected. */if (! Mysql_real_connect (& mysql, "localhost", "root", "yangxin", "test", 0, NULL, 0) {printf ("connecting to Mysql error: % d from % s/n ", mysql_errno (& mysql), mysql_error (& mysql); return-1 ;}else {printf (" Connected Mysql successful! /N ");}/* close connection */mysql_close (& mysql); return 0 ;}
    
   
  
 
Note:

If the dyld: Library not loaded: libmysqlclient.18.dylib error occurs, the dynamic Library of mysql is not linked to the/usr/lib directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.