<?Php
echo phpinfo();
?>
You should see the details about the SQLite3 like this if the same is available.

//$my_conn = new SQLite3('my_db.db');// same path as file execution
//$my_conn = new SQLite3('D:\\my_db\\my_db.db');// Full path with file name
$my_conn = new SQLite3(dirname(__FILE__).'/my_db.db'); // same location
Once our connection is established we can collect some records from a table. Note that here we already have student table with some records.
$my_conn = new SQLite3('my_db.db'); // connection to db
$sql="SELECT * FROM student "; // Query to collect records
echo "<table>";
$results = $my_conn->query($sql);
while ($row = $results->fetchArray()) {
echo "<tr ><td>$row[id]</td><td>$row[name]</td></tr>";
}
echo "</table>";
You can download the sample SQLite database with student table from here also. <?Php
$my_conn = new SQLite3('my_db.db'); // create database in same location
$sql="CREATE TABLE IF NOT EXISTS
student(id integer primary key,
name text,
class text,
mark integer,
gender text
)";
$my_conn->exec($sql); // Create table
$sql="INSERT INTO `student`
(`id`, `name`, `class`, `mark`, `gender`) VALUES
(1, 'John Deo', 'Four', 75, 'female'),
(2, 'Max Ruin', 'Three', 85, 'male'),
(3, 'Arnold', 'Three', 55, 'male'),
(4, 'Krish Star', 'Four', 60, 'female'),
(5, 'John Mike', 'Four', 60, 'female'),
(6, 'Alex John', 'Four', 55, 'male'),
(7, 'My John Rob', 'Five', 78, 'male'),
(8, 'Asruid', 'Five', 85, 'male'),
(9, 'Tes Qry', 'Six', 78, 'male'),
(10, 'Big John', 'Four', 55, 'female'),
(11, 'Ronald', 'Six', 89, 'female'),
(12, 'Recky', 'Six', 94, 'female'),
(13, 'Kty', 'Seven', 88, 'female'),
(14, 'Bigy', 'Seven', 88, 'female'),
(15, 'Tade Row', 'Four', 88, 'male'),
(16, 'Gimmy', 'Four', 88, 'male'),
(17, 'Tumyu', 'Six', 54, 'male'),
(18, 'Honny', 'Five', 75, 'male'),
(19, 'Tinny', 'Nine', 18, 'male'),
(20, 'Jackly', 'Nine', 65, 'female'),
(21, 'Babby John', 'Four', 69, 'female'),
(22, 'Reggid', 'Seven', 55, 'female'),
(23, 'Herod', 'Eight', 79, 'male'),
(24, 'Tiddy Now', 'Seven', 78, 'male'),
(25, 'Giff Tow', 'Seven', 88, 'male'),
(26, 'Crelea', 'Seven', 79, 'male'),
(27, 'Big Nose', 'Three', 81, 'female'),
(28, 'Rojj Base', 'Seven', 86, 'female'),
(29, 'Tess Played', 'Seven', 55, 'male'),
(30, 'Reppy Red', 'Six', 79, 'female'),
(31, 'Marry Toeey', 'Four', 88, 'male'),
(32, 'Binn Rott', 'Seven', 90, 'female'),
(33, 'Kenn Rein', 'Six', 96, 'female'),
(34, 'Gain Toe', 'Seven', 69, 'male'),
(35, 'Rows Noump', 'Six', 88, 'female')";
$my_conn->exec($sql); // insert 35 rows of data
echo 'Number of rows inserted: ', $my_conn->changes();
echo '<BR>Last inserted row ID : ', $my_conn->lastInsertRowID() ;
?>
backup() returns true on success. We will create one backup database using our main database.
$my_conn = new SQLite3('my_db.db');// Connect to existing database
$my_conn_backup = new SQLite3('D:\\my_db\\backup.db'); // location with file name
if($my_conn->backup($my_conn_backup)){
echo " Backup database is created ";
}else{
echo " Failed to create backup database ";
}
SELECT changes()
More on sqlite3 changes() function
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.