php sqlite - copy table to another database -


i want copy table db file fail , can't why. code:

 $db = new sqlite3($_server['document_root']."/db/098765.db");  $sql = "attach database 'admin.db' admin ;          insert 'table-1' select * 'admin.table-1';";  $db->query($sql); 

i've read questions on topic on site, no answer helped me.

giving full path attach database doesn't work. creating table before inserting data doesn't work.

  1. properly quote database object identifiers (table/column names etc) in insert statement. use use double quotes instead of single ones, string literals. better yet don't use dashes or other restricted characters in object names if possible (stick alphanumerics , underscore).

  2. use exec() instead of query()

$dbpath = $_server['document_root']; $admindbpath = $dbpath; // or else  $db = new sqlite3("$dbpath/db/098765.db"); $db->exec("attach database '$admindbpath/admin.db' admin"); $db->exec('insert "table-1" select * admin."table-1"');      ^^^^              ^       ^                     ^       ^ 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -