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.