Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP Sqlite
Scenario:
 
Has a c++ .exe application writes and reads a sqlite database every one second.
Has a php file writes and reads the same sqlite database every one second.
 

Problem:
Journal files are created locking the database, i want to turn off the journal files completely.
 

code:
on the c++ side this is the code to turn off the journal files:
 
sqlite3_exec(database, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage);
sqlite3_exec(database, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage);
sqlite3_exec(database, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage);
sqlite3_exec(database, "PRAGMA temp_store=OFF", NULL, NULL, &errorMessage);
 
The above code is working fine, so if only the .exe application is accessing the db no journal files are created. But from the php side the journal files are being created.
 
So from the php pdo side what statements should i use to turn off the journal files?
Posted 9-May-13 4:31am
amarasat1.3K
Comments
Zoltán Zörgő at 9-May-13 9:51am
   
Have you tried: $query = sqlite_exec($database, "PRAGMA journal_mode=OFF", $error);?
amarasat at 9-May-13 10:57am
   
I understood the issue now, i asked for a solution in php pdo, but the solution you gave me is the regular php sqlite function. Please let me iknow how do i turn off journal mode using php pdo
amarasat at 9-May-13 10:14am
   
global $database, $error;
$database = new PDO($dir) or die("cannot open the database");
 
$mainQuery = sqlite_exec($database, "PRAGMA journal_mode=OFF", $error);
if(!$database->query($mainQuery))
{
echo "Unable to turn off journal";
}
 
error:
<br />
Warning: sqlite_exec() expects parameter 1 to be resource, object given in C:\xx\xx\.php on line 21<br />
Unable to turn off journal
amarasat at 9-May-13 10:25am
   
$mainQuery = "sqlite_exec($database, PRAGMA journal_mode=OFF, $error)";
 
error:
<br />
Catchable fatal error: Object of class PDO could not be converted to string in C:\xx\xx\.php on line 21<br />
 
in both the comments line 21 is $mainQuery =
Zoltán Zörgő at 9-May-13 15:41pm
   
Of course you can not mix pdo with regular one. Try this:
$db = new PDO("sqlite: myDatabaseFile.sqlite");
$db->query("PRAGMA synchronous = OFF");
amarasat at 13-May-13 12:06pm
   
Yes that's what i have tried and it has worked. I also have to turn off temp_store and synchronous to get a full journal less state. thanks for your help.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100