vc6.0 compile successful copy code to pay attention to the coding of the full angle half angle problem
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <winsock2.h>w
#pragma comment (lib, "Ws2_32")
#pragma comment (lib, "Libmysql")
#include "mysql.h"
#include <string>
using namespace Std;
int main (int argc, char* argv[])
{
int res,j;
String str;
Char sql[200];
MySQL MySQL;
Mysql_res *resultset;
Mysql_row ROW;
Mysql_init (&mysql);//Initialize MySQL structure
Connect this machine, username is root, password is hope, database is hope, Port is 3306
if (!mysql_real_connect (&mysql, "localhost", "root", "hope", NULL, 3306, NULL, 0))
{
printf ("\ n DB connection Error!");
}
Else
{
printf ("\ n database connection succeeded!\n"); Insert a piece of data into a database
Getline (CIN,STR);
int size=str.size ();
Str.copy (Sql,str.size (), 0);
Char upper[200];
for (int i=0;i<size;++i)
{
Upper[i]=static_cast<char> (ToUpper (str[i));
}
Upper[i]= ' ";
res = mysql_query (&mysql,upper);
if (!res)
{
printf ("Insert%lu row data successfully!\n", (unsigned long) mysql_affected_rows (&mysql));
}
else printf ("Insert data failed!\n");
/*DDL statement
res = mysql_query (&mysql, "TRUNCATE TABLE student");
if (!res)
{
printf ("Clear data successfully!\n");
}
else printf ("Empty data failed!\n");
*/
if (mysql_query (&mysql, "select * from Hope.student"))
{
printf ("Database query error occurred");
}
Else
{
Retrieving data
printf ("\ n query data is: \ n");
ResultSet = Mysql_store_result (&mysql);//Get result set
if (mysql_num_rows (resultset)!= NULL)
{
unsigned __int64 numrows = mysql_num_rows (resultset); Get the number of records in a result set
int numfields = Mysql_num_fields (resultset);//Get the number of fields in the table
printf ("%d Row records,%d fields per line.") ", NumRows, Numfields);
j = 1;
while (row = mysql_fetch_row (resultset))
{
int i = 0;
printf ("\ n line%d:", j);
for (i = 0; i < numfields; i++)
{
fprintf (stdout, "%s", Row[i]); Print field values
}
j + +;
}
}
Else
{
printf ("\ n no query results!");
}
Mysql_free_result (resultset); Releasing the result set
}
}
Mysql_close (&mysql); Releasing a database connection
Fgetchar ();
return 0;
}
Resources
String is one of the C + + standard libraries that encapsulates the manipulation of strings
To convert a string to char* there are 3 methods:
1.Data
Such as:
String str= "abc";
Char *p=str.data ();
2 . C_str
such as: string str= "GDFD";
Char *p=str.c_str ();
3. Copy
Like what
String str= "Hello";
Char p[40];
Str.copy (p,5,0); Here 5, representing a copy of several characters, 0 represents the location of the copy
* (p+5) = ' "; To manually add a terminator
cout < <p;
Sample programs:
#include <iostream>
#include <string>
using namespace Std;
int main ()
{
String line;
Getline (Cin,line);
Char str[20];
int size=line.size ();
Line.copy (Str,line.size (), 0);
Char str[20]= "Liuyanbo";
Char upper[20];
for (int i=0;i<size;++i)
{
Cout<<static_cast<char> (ToUpper (str[i));
Upper[i]=static_cast<char> (ToUpper (str[i));
}
Upper[i]= ' ";
cout<<upper<<endl;
return 0;
}