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

cron - how to properly run Python script with crontab on every system startup -

elasticsearch - Is the order of operations guaranteed in a bulk update? -

Slow performance first queries on SQL Azure -