Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Scenario:

Turning off journal mode using PHP::PDO does not work


PHP
try
{
  $dir = 'sqlite:C:/SQLite/'.$FileName.'.sqlite';
  $database  = new PDO($dir) or die("cannot open the database");
}
catch(Exception $e)
{
    echo $e->getMessage();
    echo "Unable to create database";
}
$mainQuery = "PRAGMA journal_mode=OFF";
$resultm = $database->query($mainQuery);
$arr = $resultm->errorInfo();
print_r($arr);

$mainQuery1 = "PRAGMA synchronous=OFF";
$resultm = $database->query($mainQuery1);
$arr1 = $resultm->errorInfo();
print_r($arr1);

$mainQuery2 = "PRAGMA count_changes=OFF";
$resultm = $database->query($mainQuery2);
$arr2 = $resultm->errorInfo();
print_r($arr2);

$mainQuery3 = "PRAGMA temp_store=OFF";
$resultm = $database->query($mainQuery3);
$arr3 = $resultm->errorInfo();
print_r($arr3);


Here is the output:

VB
Array
(
    [0] => 00000
    [1] =>
    [2] =>
)
Array
(
    [0] => 00000
    [1] =>
    [2] =>
)
Array
(
    [0] => 00000
    [1] =>
    [2] =>
)
Array
(
    [0] => 00000
    [1] =>
    [2] =>
)


And SQLSTATE error code 00000 means Successful Execution.

Now, if i open the created sqlite database using "SQLITE Manager" add on in firefox. In the "DB Settings" tab i see Journal Mode : delete and Synchronous : off. How the hell do i turn off the journal mode completely?

If i try to change the Journal Mode DB setting in the "SQLITE Manager", it will not change because a table exists which i am creating later in the code. This makes sense according to the documentation. But why isn't the journal mode turned off in the first place but stays in default delete.
Posted
Updated 21-Jun-13 11:22am
v2

1 solution

The answer is simple!! In PHP PDO Sqlite, or in Sqlite in general, we cannot turn off the journal mode completely. A journal mode can be turned off temporarily per single session to improve performance. If you want to turn off the journal mode permanently, then you have to turn if off for each and every single session using the code i gave above.

Note: Session means, opening and closing the database once.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900