When i was looking for database for my project. i was thinking to implement Mysql and i found out it was quite hard to setup and use in c++.
Then i found sqlite for c++ article i read about it and i came up with this template.
I Will try to create step by step tutorial about it.
I try to make things simple as possible.
- db : On this folder we will store all our databases
- sqlite : this folder contains sqlite header file.
NOTE : You can move into header file folder if it is large projects and have lots of library
- src : It consists of all cpp files
- main.cpp : here you write your codes.
#include <iostream>
#include "sqlite/sqlite3.h"
using namespace std;
int main()
{
// Pointer to SQLite connection
sqlite3* db;
// Save the connection result
int exit = 0;
exit = sqlite3_open("db/example.db", &db);
// Test if there was an error
if (exit) {
cout << "DB Open Error: " << sqlite3_errmsg(db) << endl;
} else {
cout << "Opened Database Successfully!" << endl;
}
// Close the connection
sqlite3_close(db);
return (0);
}
compile:
g++ main.cpp -o main -l sqlite3
./main
Open up your terminal and type following
mingw32-make -f MakeFile
type following on terminal
g++ main.cpp -o main -l sqlite3
Happy Coding ๐
Keep Learning ๐ \