2013-08-04 173 views
0

如何創建一個SQLite數據庫與PHP/PDO從另一個現有的SQLite數據庫中導入數據庫的一個表?如何將SQLite表導入帶有PHP/PDO的新數據庫?

這是我的僞代碼以爲至今:

$existing_database = 'database1.sqlite'; 
try 
{ 
    $dbhandle = new PDO('sqlite:database2.sqlite'); 

    $dbhandle->exec("CREATE TABLE new_table IMPORT table from $existing_database"); 

    $dbhandle = NULL; 
    } 

catch(PDOException $e) 
    { 
    print 'Exception : '.$e->getMessage(); 
    } 
+1

這個問題實際上與PHP/PDO無關。 PDO只是一個運行查詢的界面。無論您的數據庫支持哪種查詢,PDO都可以發送它。所以你必須要求Sqlite查詢,而不是PDO代碼。 –

回答

0

existing_database = 'database1.sqlite';

try 
{ 
    $dbhandle = new PDO('sqlite:database2.sqlite'); 

    $dbhandle->exec("ATTACH DATABASE 'database1.sqlite' AS existing_database"); 

    $dbhandle->exec('CREATE TABLE table AS SELECT * FROM existing_database.table'); 

    $dbhandle = NULL; 
    } 

catch(PDOException $e) 
    { 
    print 'Exception : '.$e->getMessage(); 
    } 
相關問題