I am trying to enable foreign key constraint of sqlite database from my php script.
I tried :
shell_exec('sqlite ex.db');
shell_exec('PRAGMA foreign_keys = ON');
echo $isEnabled = shell_exec('PRAGMA foreign_keys');
But I am not getting $isEnabled as 1 . In fact I am not getting anything as output.
Thanks.
Why you dont use the built-in SQLite driver?
According your problem:
shell_exec()(as the name suggest) executes shell commands. This means, that you try to execute three (!) shell commands, but you want to execute one and then you want to execute 2 more commands within the interactive sqlite3-process you started before. This is not possible this way. Maybe you can play around withstdin, but because PHP comes with SQLite3-support I don’t see a reason to make it more complex, that it needs to be.