如何使用PHP / PDO将SQLite表导入新数据库?

时间:2013-08-04 09:55:35

标签: php sqlite pdo

如何使用PHP / PDO从另一个现有SQLite数据库导入数据库的一个表来创建SQLite数据库?

这是我到目前为止在伪代码中的想法:

$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 个答案:

答案 0 :(得分: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();
  }