php - Restore a postgresql dump (.sql file) without the command line? -


scenario:

i have built php framework uses postgresql database. framework comes shipped .sql file dump of default tables , data framework requires.

i want able run sql file client (php), rather command line, in order import data. because have come across server setups accessing command line not possibility, and/or running commands isn't possible (pg_restore may not accessible php user example).

i have tried splitting .sql file , running query using pg_sql php extension, because dump file uses copy commands create data, doesn't seem work. seems because copy used, .sql file expects imported using pg_restore command (unless missing something?).

question:

so question is, how can restore .sql dump, or create .sql dump in way can restored via client (php) rather command line?

for example:

<?php pg_query(file_get_contents($sqlfile)); ?> 

rather than:

$ pg_restore -d dbname filename 

example of error:

i using pgadmin iii generate .sql dump, using "plain" setting. in .sql file, data inserted table looks this:

copy core_classes_models_api (id, label, class, namespace, description, "extensionname", "readaccess") stdin; 1   data    data    \\core\\components\\apis\\data  data api    core    310 \. 

if run above sql within pgadmin iii query window, following error:

error:  syntax error @ or near "1" line 708: 1 data data \\core\\components\\apis\\data data api core... 

this bit tricky find, after investigation, appears pg_dump's "plain" format (which generates plain-text sql file) generates copy commands rather insert commands default.

looking @ specification pg_dump here, found option --inserts. configuring option allow dump create insert commands create copy commands.

the specification state:

this make restoration slow; useful making dumps can loaded non-postgresql databases. however, since option generates separate command each row, error in reloading row causes row lost rather entire table contents.

this works purposes however, , others same problem!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -