How to connect to the SQLITE using PDO?

In PDO(PHP Data Object) you can also connect with SQLITE. As per below example you can easily  understand.

You can connect with SQLITE using two ways.

  • File
  • Memory

Using File

using file we have to create a one file like .sdb extension and give the path as per below example.

<?php
	try
	{
		$dbh = new PDO("sqlite:PATH/DATABASENAME.sdb");
		echo "Connection Successful";
	}
	catch (PDOException $e)
	{
		print "Error!: " . $e->getMessage();
		die();
	}
?>

Using Memory

Using memory we can create a database in memory and we can use for as per requirement.

<?php
	try
	{
		$dbh = new PDO("sqlite::memory");
		echo "Connection Successful And Database created in Memory";
	}
	catch (PDOException $e)
	{
		print "Error!: " . $e->getMessage();
		die();
	}
?>

hope you got the proper solutions.

Advertisements

Leave your comments

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s