Step 1: Prepare for gcc. After installation, you need to install some class libraries. There will be no many errors such as sudoapt-getinstallg ++, glibc, glibc-source, build-essential, libmysql ++ dev, libmysqlclient15off, libmysqlclient15-dev above these things, I do not know what really useful, anyway, these I have installed the second step: Sample program (Others) # I
Step 1: Prepare
Gcc: some class libraries will be installed after installation, so there won't be many errors
Sudo apt-get install g ++, glibc, glibc-source, build-essential, libmysql ++ dev, libmysqlclient15off, libmysqlclient15-dev
I don't know which of the above are actually useful. I have installed them all.
Step 2:
Example Program (others)
# Include
# Include
# Include
# Include
Int main (){
MYSQL * mysql;
MYSQL_RES * res;
MYSQL_ROW row;
Char query [1024];
Int t, r;
Mysql = mysql_init (NULL );
If (! Mysql_real_connect (mysql, "test", "root ",
"123", "test", 0, NULL, 0 ))
{
Printf ("Error connecting to database: % s \ n", mysql_error (mysql ));
}
Else printf ("Connected... \ n ");
Sprintf (query, "select * from first ");
T = mysql_query (mysql, query );
If (t)
{
Printf ("Error making query: % s \ n ",
Mysql_error (mysql ));
}
Else printf ("Query made... \ n ");
Res = mysql_use_result (mysql );
For (r = 0; r
Row = mysql_fetch_row (res );
If (row <0) break;
For (t = 0; t
Printf ("% s", row [t]);
Printf ("\ n ");
}
Mysql_close (mysql );
Return 0;
}
Then gcc test. c-lmysqlclient
In addition, # include may also cause problems. If you need to change it to an absolute path, try again.