MySQL program of VC

Source: Internet
Author: User

It is important to use a data volume in your program. If you already have an available MySQL server, you can use the following method in the VC to implement data migration.

1. Find the include file category under MySQL (win32) Security Program, and add it to the VC header file category list;

(Vc6-> options-> directories-> Add this category)

(Vc2005-> tool-> Option-> solution-> VC ++ project-> show the content of the following content-> include files-> Add in this example)

2. Find the Lib file quota under MySQL (win32) Security Program, and add it to the VC program file Quota List;

(Vc6-> options-> directories-> Add this category)

(Vc2005-> Tools-> options-> solutions-> VC ++ projects-> displays the following contents-> upload files-> Add in this example, note: lib/debug or lib/OPT)

3. Create a new project and test the following representative;

 

// Mysql. cpp: defines the entry point for the console application.
//

# Include "stdafx. H"
# Include <stdio. h>
# Include <Winsock. h>
# Include <mysql. h>
# Include <windows. h>

# Pragma comment (Lib, "libmysql. lib ")


Int main (INT argc, char * argv [])
...{
Unsigned short Port = 3306;
Char * IPaddress = "192.168.31.56 ";
Char * username = "root ";
Char * Password = "";
Char * dbname = "sas_1_2_0 ";

Printf ("start ...");

MySQL * ssock;
// Char execsql [500];

Ssock = (MySQL *) malloc (sizeof (MySQL ));

// In some versions, Initialization is not required. You can refer to MySQL. h and readme.
Mysql_init (ssock );
If (ssock = NULL)
...{
Printf ("eror: MySQL ssock init error .");
Return false;
}

// Receives the specified data volume
Ssock = mysql_real_connect (ssock, IPaddress, username, password, null, port, null, 0 );
If (! Ssock)
...{
Printf ("conn fail ...");

// Memcpy (EEE, mysql_error (ssock), 20 );
// Fprintf (stderr, "failed to connect to database: Error: % s", mysql_error (ssock ));

// Printf ("% C", eee );
Unsigned int mtint = mysql_errno (ssock );
// Printf ("% d ");
Return false;
}

If (mysql_select_db (ssock, dbname )! = 0)
...{
Printf ("select dB error .");
Return false;
}

Printf ("version = % d", mysql_get_server_version (ssock ));
// Exec my execsql string
// Sprintf (execsql, "create table girls (name char (10), age INT )");
// Mysql_real_query (ssock, execsql, strlen (execsql ));
Mysql_close (ssock );

Printf ("end ...");
Return true;
}

 

 

3. You can just run it.

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.