Softaculous


Topic : Database created but not importing SQL


Posted By: LeonardChallis on October 31, 2015, 12:00 pm
I've created a custom package and it is running nicely, apart from the fact that the database isn't being setup correctly.

In my install.php I have the following:

PHP Code

 $sqlPath '/tmp/' $software['softname'] . '.sql';
sdb_export('localhost''some_db''password''someuser'$sqlPath);
sdb_import($sqlPath); 



After the installation runs, the SQL dump file appears in the /tmp folder correctly. However, the sub_import() function isn't running correctly.

I don't see any errors, and manually importing the SQL to the same database from the dump file works fine. I may be looking in the wrong place but my /var/softaculous/error_log is empty and I can't find anything in other logs I've seen - maybe I'm missing the correct one?

If someone can suggest something to try next I'd appreciate it.

Posted By: Brijesh on October 31, 2015, 2:45 pm | Post: 1
Hi,

sdb_import() takes the parameter as the filename and the file should be available at :
/var/softaculous/SOFTNAME

You just need to pass the filename, you cannot pass the full path to the SQL file.

Or you can read that SQL file and then execute the query using sdb_query() function :
PHP Code

 sdb_query($data$__settings['softdbhost'], $__settings['softdbuser'], $__settings['softdbpass'], $__settings['softdb']); 



-----------------------
Webuzo - Multi User Hosting Control Panel
AMPPS - Best WordPress/PHP/MySQL development tool

Posted By: LeonardChallis on October 31, 2015, 3:24 pm | Post: 2
Hey Brijesh, thanks so much for replying!

In the documentation I read this:

sdb_import($parameter1) - This function is used to execute the database queries.
1st Parameter (required) = String $parameter1 is the Absolute path of the file which contains the database queries to be executed.

From what you've said, does this mean the documentation is wrong, and it's actually the relative path from /var/softaculous/softname?

If so, and presuming I want to dump a database first, how would I do this? I have tried doing something like this:

PHP Code

 sdb_export('localhost''some_db''password''someuser'$software['soft name'] . '.sql');
sdb_import($software['softname'] . '.sql'); 



But that doesn't work. I presume this is because of permissions? But I did a touch mysoftname.sql and chown myuser:myuser mysoftname.sql and re-ran installing the package but that didn't work.

As noted in my first post, it works if I try write to /tmp.

So, if I want to dump a database and place it in the package directory then import it, what's the correct way to go about it please?

Kind regards for your help!

Posted By: Brijesh on November 2, 2015, 9:30 am | Post: 3
Hi,

It looks like the documentation was incorrect for the sdb_import() function. I have updated it :
http://www.softaculous.com/docs/Making_Custom_Package#Explanation_of_Important_functions

To achieve your purpose you can use the following code :
PHP Code

 $sqlPath '/tmp/' $software['softname'] . '.sql';
sdb_export('localhost''some_db''password''someuser'$sqlPath);

$queries sfile($sqlPath);
sdb_query($queries'localhost''someuser''password''some_db'); 



Edited by Brijesh : November 2, 2015, 10:01 am

-----------------------
Webuzo - Multi User Hosting Control Panel
AMPPS - Best WordPress/PHP/MySQL development tool

Posted By: LeonardChallis on November 2, 2015, 9:53 am | Post: 4
Thanks again, that makes sense.

Did you mean to write sdb_query for the last line of PHP there?

Posted By: Brijesh on November 2, 2015, 10:02 am | Post: 5
Hi,

Yes it should be sdb_query()

I have edited the post.

-----------------------
Webuzo - Multi User Hosting Control Panel
AMPPS - Best WordPress/PHP/MySQL development tool

Posted By: purjayadi on July 18, 2019, 10:00 am | Post: 6
i have some issue about this, i have already try this

PHP Code

 $sqlPath '/tmp/' $software['cust'] . '.sql'
    
sdb_export('[[softdbhost]]''[[softdb]]''[[softdbpass]]''[[softdbuser]]'$sqlPath); 
    
    
$queries sfile($sqlPath); 
    
sdb_query($sqlPath'[[softdbhost]]''[[softdbuser]]''[[softdbpass]]''[[softdb]]'); 



but not work

Posted By: Brijesh on July 19, 2019, 9:05 am | Post: 7
Hi,

As per our discussion over email you have managed to get this working.

Let us know if you still face any issues.

-----------------------
Webuzo - Multi User Hosting Control Panel
AMPPS - Best WordPress/PHP/MySQL development tool

Posted By: purjayadi on July 19, 2019, 9:16 am | Post: 8
solved
Quote From : Brijesh July 19, 2019, 9:05 am
Hi,

As per our discussion over email you have managed to get this working.

Let us know if you still face any issues.

Powered By AEF 1.0.8 © 2007-2008 Electron Inc.