Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php脚本启用sqlite DB的外键约束_Php_Sqlite - Fatal编程技术网

从php脚本启用sqlite DB的外键约束

从php脚本启用sqlite DB的外键约束,php,sqlite,Php,Sqlite,我试图从php脚本中启用sqlite数据库的外键约束 我试过: shell_exec('sqlite ex.db'); shell_exec('PRAGMA foreign_keys = ON'); echo $isEnabled = shell_exec('PRAGMA foreign_keys'); 但是我没有像1那样获得$isEnabled。事实上,我没有得到任何东西作为输出 谢谢。为什么不使用内置的SQLite驱动程序 $con = new SQLite3('ex.db'); $c

我试图从php脚本中启用sqlite数据库的外键约束

我试过:

shell_exec('sqlite ex.db');

shell_exec('PRAGMA foreign_keys = ON');

echo $isEnabled = shell_exec('PRAGMA foreign_keys');
但是我没有像
1
那样获得
$isEnabled
。事实上,我没有得到任何东西作为输出


谢谢。

为什么不使用内置的SQLite驱动程序

$con = new SQLite3('ex.db');
$con->exec('PRAGMA foreign_keys = ON;');
var_dump($con->query('PRAGMA foreign_keys;')->fetchArray());

根据您的问题:
shell\u exec()
(顾名思义)执行shell命令。这意味着,您尝试执行三个(!)shell命令,但您希望执行一个,然后在之前启动的交互式sqlite3进程中再执行两个命令。这样做是不可能的。也许你可以使用stdin,但是由于PHP附带了SQLite3支持,我认为没有理由让它变得更复杂。为什么不使用内置的SQLite驱动程序呢

$con = new SQLite3('ex.db');
$con->exec('PRAGMA foreign_keys = ON;');
var_dump($con->query('PRAGMA foreign_keys;')->fetchArray());
根据您的问题:
shell\u exec()
(顾名思义)执行shell命令。这意味着,您尝试执行三个(!)shell命令,但您希望执行一个,然后在之前启动的交互式sqlite3进程中再执行两个命令。这样做是不可能的。也许您可以使用stdin,但由于PHP附带SQLite3支持,我不认为有必要将其变得更复杂。

在shell脚本中有一节使用SQLite3:

当使用两个参数启动sqlite3程序时,第二个参数 参数传递给SQLite库进行处理,查询 结果以列表模式打印在标准输出上,程序 出口

因此您可以尝试
sqlite3ex.db'PRAGMA foreign_keys=ON;PRAGMA foreign_keys'

中有一节在shell脚本中使用sqlite3:

当使用两个参数启动sqlite3程序时,第二个参数 参数传递给SQLite库进行处理,查询 结果以列表模式打印在标准输出上,程序 出口


因此您可以尝试
sqlite3ex.db'PRAGMA foreign_keys=ON;PRAGMA外键

也应该与PDO SQLite一起使用,因为查询是按原样发送的。甚至方法名(
exec()
/
queryy()
)也是相同的;)只有
query()
的返回值略有不同,但更简单:
query('PRAGMA foreign_key')->fetchColumn(0)
感谢KingCrunch,这是我的另一个新应用,我将codeigniter与sqlite3一起使用……所有数据库连接设置都在database.php:$active_group=“default”$活动记录=真$db['default']['hostname']=$appip$db['default']['username']=“”$db['default']['password']=''$db['default']['database']=“sqlite:ex.db”$db['default']['dbdriver']=“pdo”$db['default']['dbprefix']=“”;等等…我怎么还能启用外键?再次感谢…我也在CI论坛上发布了相同的que,但还没有回复…-(请注意,我在我的模型构造函数中使用$this->{$this->db_group_name}->query('PRAGMA foreign_keys=on;'))也应该使用PDO_SQLite,因为查询是按原样发送的。甚至方法名(
exec()
/
queryy()
)都是相同的;)只有
query()
的返回值略有不同,但更简单:
query('PRAGMA foreign_key')->fetchColumn(0)
感谢KingCrunch,这是我的另一个新应用,我将codeigniter与sqlite3一起使用……所有数据库连接设置都在database.php:$active_group=“default”$活动记录=真$db['default']['hostname']=$appip$db['default']['username']=“”$db['default']['password']=''$db['default']['database']=“sqlite:ex.db”$db['default']['dbdriver']=“pdo”$db['default']['dbprefix']=“”;等等…我怎么还能启用外键?再次感谢…我也在CI论坛上发布了相同的que,但还没有回复…-(请注意,我在模型构造函数中使用$this->{$this->db_group_name}->query('PRAGMA foreign_keys=on;')