How to execute ATTACH DATABASE using PHP SQLite3

I am using PHP (version 5.3.13) with sqlite3 enabled (version 0.7-dev). I want to be able to use the SQLITE3 feature for ATTACH DATABASE so that I can execute JOINed queries, but every time I do ATTACH DATABASE, it fails.

$dbmain = new SQLite3('main.s3db'); $results = $dbmain->exec("ATTACH DATABASE support.s3db AS ckj"); var_dump($results); 

var_dump always shows false, and I can never request ckj.

+4
source share
1 answer

You need to specify the full path.

 $myroot = $_SERVER["DOCUMENT_ROOT"]; $dbmain = new SQLite3('main.s3db'); $cmd = "ATTACH DATABASE '".$myroot."/support.s3db' AS ckj"; $results = $dbmain->exec($cmd); var_dump($results); 

will work correctly.

+5
source

All Articles