Execute SQL file from PHP!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Execute SQL file from PHP!!

Post 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
silenceghost
Forum Newbie
Posts: 22
Joined: Sun Oct 19, 2008 3:25 am

Re: Execute SQL file from PHP!!

Post 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);       
    }
 
 
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Execute SQL file from PHP!!

Post by pcoder »

Thanks for the reply. But i am searching the equivalent process in oracle.
Post Reply