Page 1 of 1

Execute SQL file from PHP!!

Posted: Sun Oct 19, 2008 12:05 am
by pcoder
Hi,
I am using oracle as database. The script files are maintained in sql file.
I have to execute these sql script from PHP.
Through sqlplus, we can easily run the script like:

Code: Select all

 
@c:\test.sql;
 
And i am searching the stuff to some extent similar to this from PHP. Is this possible??

Thanks

Re: Execute SQL file from PHP!!

Posted: Sun Oct 19, 2008 4:42 am
by silenceghost

Code: Select all

 
 
 
  $dbhost = 'localhost';
  $dbuser = 'root';
  $dbpass = 'password';
  $db = 'test';
  $file ='/tmp/file_restore.sql';
 
    if ($dbpass != '') {
        $cmd = '/usr/bin/mysql -h '.$dbhost.' -u '.$dbuser.' -p 
'.$dbpass.' < '.$file;
        exec($cmd,$out,$retval);   
    } else {
        $cmd = '/usr/bin/mysql -h '.$dbhost.' -u '.$dbuser.' < '.$file;
        exec($cmd,$out,$retval);       
    }
 
 

Re: Execute SQL file from PHP!!

Posted: Sun Oct 19, 2008 6:20 am
by pcoder
Thanks for the reply. But i am searching the equivalent process in oracle.