A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to create SQLite database dynamically in Linux
Q:

C program to create SQLite database dynamically in Linux

0

C program to create SQLite database dynamically in Linux

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will create a database using the sqlite3_open() function dynamically in Linux.

Program/Source Code:

The source code to create a SQLite database dynamically is given below. The given program is compiled and executed successfully on Ubuntu 20.04.

//C program to create database dynamically in linux.

#include <sqlite3.h>
#include <stdio.h>

int main(void)
{
    sqlite3* db_ptr;
    int ret = 0;

    ret = sqlite3_open("MyDb.db", &db_ptr);

    if (ret == SQLITE_OK) {
        printf("Database created successfully\n");
    }

    sqlite3_close(db_ptr);

    return 0;
}

Output:

$ gcc create_db.c -o create_db -lsqlite3 -std=c99
$ ./create_db 
Database created successfully

In the above program, we included the sqlite3.h header file to uses SQLITE related functions. Here, we created "MyDb.db" database using sqlite_open() function. The sqlite_open() function is used to open an existing database and if the database is not present then it will create a specified database automatically.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now