-4

I write this:

$db = new PDO("sqlite:$dbname");
$db->exec("PRAGMA journal_mode = WAL;");
#.....                        
$wal_status = $db->exec("PRAGMA journal_mode;");
echo "WAL-status: ".$wal_status;

The www-page says: "WAL-status: 0" ---I think this means: WAL is not activated.

What must I do? Thx in advance for your hints.

josefus
  • 47
  • 4
  • 1
    Perhaps it is an in-memory database? See the last paragraph here: https://www.sqlite.org/pragma.html#pragma_journal_mode – KIKO Software Jul 15 '23 at 12:21
  • I don't think so. In a config.php I specified a disk file xxxsqlite.db. This db is called by my code shown above ($dbname), and it is stored on the disk of my webspace provider. – josefus Jul 15 '23 at 12:48
  • You're using [exec()](https://www.php.net/manual/en/pdo.exec.php) which returns the number of affected rows. Zero is the correct number. Maybe [query()](https://www.php.net/manual/en/pdo.query.php) will work as you expect? I have not tested this... – KIKO Software Jul 15 '23 at 13:15

1 Answers1

-1

I asked chatGPT, and it answered:

Do not use $wal_status = $db->exec("PRAGMA journal_mode;"); but use $wal_status = $db->query("PRAGMA journal_mode;")->fetchColumn();

chatGPT also said the reason, I don't write it here. It's proposal works good, problem is solved.

josefus
  • 47
  • 4
  • 4
    Next time, don't use chatGPT, but read the documentation. You can solve more problems quicker that way. It might even help you to prevent making similar mistakes in the future. – KIKO Software Jul 15 '23 at 13:25