Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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:

C++
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
Comments
Zoltán Zörgő 9-May-13 9:51am    
Have you tried: $query = sqlite_exec($database, "PRAGMA journal_mode=OFF", $error);?
amarasat 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 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 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ő 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");

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