Xcode environment Configuration MySQL

Source: Internet
Author: User
Tags mysql code mysql connect

The default MySQL installation directory for this article is/usr/local/mysql

    1. Add/usr/local/mysql/includ to the project's header search paths

    

2. Add/usr/local/mysql/li to the project's Library search paths

    

3. Add-lm-lz-lmysqlclient in the other Linker flags of the project

    

The 4.c language link MySQL code is as follows:

if(!mysql_init (&conn)) {fprintf (stderr,"init mysql failed! no free memory!\n"); Exit (0); }Else{fprintf (stdout,"init MySQL successful!\n"); }//Initializing the database    if(!mysql_real_connect (&conn,"localhost","Root","12345","MyDB",3308Null0))        //use host name, username, password, database name, port, respectively{fprintf (stderr,"MySQL Connect failed!: Error%u (%s) \ n", Mysql_errno (&conn), Mysql_error (&conn)); Mysql_close (&conn); Exit (0); }Else{fprintf (stdout,"MySQL Connect successful!\n"); }//Link Database    if(mysql_select_db (&conn,"MyDB") {fprintf (stderr,"Use database failed!: Error%u (%s) \ n", Mysql_errno (&conn), Mysql_error (&conn)); Mysql_close (&conn); Exit (0); }Else{fprintf (stdout,"Use database succeessful!\n"); }//Select Databasemysql_query (&conn,"SET NAMES UTF8");//prevent garbled, MySQL for UTF-8 encoding

 

Xcode environment Configuration MySQL

Related Article

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.