1. Create a new folder named SQLite in/home/
#cd/Home
#mkdir SQLite
2. Write the C language code, the name is SQL.C, the code is as follows
//name:sql.c//This prog was used to test C + + API for sqlite3. It is very simple,ha! //Author:zieckey All rights reserved. //DATA:2006/11/13#include<stdio.h>#include<stdlib.h>#include"sqlite3.h" intMainvoid) {sqlite3*db=NULL; Char*zerrmsg =0; intRC; //opens the specified database file and creates a database file with the same name if it does not existrc = Sqlite3_open ("zieckey.db", &db); if(RC) {fprintf (stderr,"Can ' t Open database:%s", sqlite3_errmsg (db)); Sqlite3_close (DB); Exit (1); } Elseprintf"You have opened a sqlite3 database named Zieckey.db successfully! congratulations! There's fun! ^-^ "); Sqlite3_close (DB); //Close the database return 0; }
3. Download the source code on the Internet and put it under the new SQLite folder. http://www.sqlite.org/
4. Unzip the source code under the sqlite-autoconf-3080600.tar.gz
#tar-ZXVF sqlite-autoconf-3080600.tar.gz
There will be one more folder under the/home/sqlite/folder sqlite-autoconf-3080600
5. Compiling the code is also the most important step
# gcc-o Sql.out-l/home/sqlite/sqlite-autoconf-3080600/.libs-i/home/sqlite/sqlite-autoconf-3080600 sql.c-lsqlite3
The main meaning of the above:-L for you to install the Sqlite3 class library where the path,-I for the installation of Sqlite3 header file path and-L represents the name of the executable program, through the above compilation, can be successful.
Sql.out is the generated executable file, SQL.C is the original file
Executing the generated code
#./sql.out
Output the following information to indicate success
You have opened a sqlite3 database named Zieckey.db successfully! congratulations! There's fun! ^-^
Using C language to connect SQLite under Linux