Code: # export decstdlib # export destring # export deusrlocal#demysqlmysql. h: location of the mysql header file installed in usingnamespacestd; stringhost database address; stringuser username; add stri C and C
Code:
# Include
# Include
# Include "/usr/local/include/mysql. h" // location of the mysql header file installed
Using namespace std;
String host = "database address ";
String user = "user name ";
String pwd = "password ";
String dbname = "database ";
String SQL = "query statement ";
Unsigned int port = 3309; # port number
Int status;
Int main (){
MYSQL * mysql;
Mysql = mysql_init (0 );
MYSQL_RES * result;
MYSQL_ROW row;
If (mysql_real_connect (mysql, host. c_str (), user. c_str (), pwd. c_str (), dbname. c_str (), port, NULL, CLIENT_FOUND_ROWS) = NULL ){
Cout <"connect failure! "<Endl;
Return EXIT_FAILURE;
} Else {
Cout <"connect success! "<Endl;
}
Mysql_set_character_set (mysql, "gbk ");
Status = mysql_query (mysql, SQL. c_str ());
If (status! = 0 ){
Cout <"query failure! "<Endl;
}
Cout <"the status is:" <status <endl;
Result = mysql_store_result (mysql );
While (row = mysql_fetch_row (result )){
Cout <row [1] <"|" <row [2] <endl;
}
Mysql_free_result (result );
Mysql_close (mysql );
}
Compile:
G ++-o test. cpp-lmysqlclient-I/usr/local/include/mysql/-L/usr/local/lib/mysql
Which of the following are used to specify the path and library file path for mysql installation, which is related to the path for mysql installation on your machine.