Click here to Skip to main content
11,802,389 members (30,341 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: PHP Sqlite

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.

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

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 3:31am
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);
echo "Unable to turn off journal";

<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)";

<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 OriginalGriff 475
1 KrunalRohit 366
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CHill60 220
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2015
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