Using PHP , call a sql inside a unix script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Using PHP , call a sql inside a unix script
# 1  
Old 10-31-2012
Lightbulb Using PHP , call a sql inside a unix script

I am running the xampp on WINDOWS, and my php script is connecting to a unix script on a different server (ssh2_connect("11.31.138.56", 22). I am running the unix script and inside this script I am calling the .sql file . The SQL is connecting to oracle db on the unix server.

But the sqlplus command is not working when called using php , but when I run the script on unix everything is working fine.

ERROR : Output: Error: mysql2.sh: line 8: sqlplus: command not found

Unix script:mysql2.sh

Code:
#!/bin/ksh

sqlplus -s XLTDB10/XLTDB10@XLTUAT1 @mysql.sql

PHP CODE:

<?php
include 'db_connect.php';
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect("11.31.138.56", 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password
if(!ssh2_auth_password($con, "uat0", "unix11")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";

// execute a command
if (!($stream = ssh2_exec($con,"sh mysql2.sh" ))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command

$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);

// Enable blocking for both streams
stream_set_blocking($errorStream, true);
stream_set_blocking($stream, true);
// Whichever of the two below commands is listed first will receive its appropriate output. The second command receives nothing
echo "Output: " . stream_get_contents($stream);
echo "Error: " . stream_get_contents($errorStream);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
// echo $data;
}
// echo $stream;
fclose($errorStream);
fclose($stream);
}
}
}
?>[/code]

Last edited by jim mcnamara; 10-31-2012 at 09:14 AM..
# 2  
Old 10-31-2012
You need to set the full path to sqlplus in the script.
This User Gave Thanks to eosbuddy For This Post:
# 3  
Old 10-31-2012
this below solution worked for me,what I did , I changed the unix script like this.

Code:
#!/bin/ksh

export ORACLE_HOME=/oravl01/oracle/11.2.0.3
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=xltuat1

/oravl01/oracle/11.2.0.3/bin/sqlplus -s XLTDB10/XLTDB10@XLTUAT1 @mysql.sql


Last edited by jim mcnamara; 10-31-2012 at 09:15 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Call SQL LOADER FROM UNIX

HI Experts, I am pretty new to scripting and i need to create a perl or shell script which should fetch a file from local directory and insert the data into a table using sql loader. This will be later added to chron job to run daily and fetch all files and load them into the table. Also i... (1 Reply)
Discussion started by: sam1234
1 Replies

2. UNIX for Dummies Questions & Answers

Call SQL LOADER FROM UNIX

HI Experts, I am pretty new to scripting and i need to create a perl or shell script which should fetch a file from local directory and insert the data into a table using sql loader. This will be later added to chron job to run daily and fetch all files and load them into the table. Also i... (1 Reply)
Discussion started by: sam1234
1 Replies

3. Shell Programming and Scripting

Call sql script from UNIX shell script

I know this question is out there in many forums, but I tried all the combinations in vain. I'm basically trying to call a sql script from a shell script. Below is my sql script (plsql.sql) DELCARE v_empno NUMBER := '&empno'; BEGIN select ename,sal from emp where empno = v_empno;... (3 Replies)
Discussion started by: FName_LName
3 Replies

4. UNIX for Dummies Questions & Answers

Call a UNIX script inside another and dont wait for it

Hi I have two scripts script1.sh and script2.sh(say this script is a long running). I want to call script2.sh inside and script1.sh,but when i call script2.sh i dont want to wait for script2 to complete and want this to run in back ground and go on next commands in script 1.sh and finally at the... (2 Replies)
Discussion started by: lijjumathew
2 Replies

5. Shell Programming and Scripting

How to call an sql script inside a while statement in KSH

Hi all, I'm trying to run an sql inside a loop which looks like this #!bin/ksh while IFS=, read var1 var2 do sqlplus -s ${USERNAME}/${PASSWORD}@${ORACLE_SID} << EOF insert into ${TABLE} ( appt_date ) values ( '${var1 }' ); ... (6 Replies)
Discussion started by: ryukishin_17
6 Replies

6. Shell Programming and Scripting

Call a pl sql function from unix

hi, I want to know how to call a pl sql function testfunction(param1,..) that returns a value and grab that value in a shell variable. Thnx in advance ---------- Post updated 03-30-10 at 11:58 AM ---------- Previous update was 03-29-10 at 03:49 PM ---------- thnx a lot jim (0 Replies)
Discussion started by: austinhell3_16
0 Replies

7. Shell Programming and Scripting

Can SQL Server call be made from unix sh

Hi, I need to make SQL Server procedure call (exec <proc name>)from unix shell script. First of all I would like to know if it is possible. I know we can do it from Oracle but not sure about SQL Server. Version: SunOS 5.8 SQL 8.0 I have made the below entry in the interface file. NSXNA267 ... (0 Replies)
Discussion started by: sspreethi
0 Replies

8. UNIX for Advanced & Expert Users

How to call SQL procedure from UNIX Shellscript ?

Hi All I would be thankful to you all if you will guide me the steps to call a stored proc. from unix shell script. that stored proc. could be parameterised or parameterless developed in SQL. Any info. in this topic would help me..... Thanks in advance.... (1 Reply)
Discussion started by: varungupta
1 Replies

9. Shell Programming and Scripting

how can I call a pl/sql funciton in unix script

who can show me how to call pl/sql function or precudure in unix script.. cheers, (6 Replies)
Discussion started by: YoYo
6 Replies

10. Shell Programming and Scripting

How to call pl/sql in unix script

sample code as following: test_sql(){ #test#echo test_sql str=`$ORACLE_BIN/sqlplus -s $user/$passwd <<EOM set verify off set heading off set feedback off #--------start pl/sql { DECLARE CURSOR pah_cs IS select id from table where letter = 'abcd';... (6 Replies)
Discussion started by: YoYo
6 Replies
Login or Register to Ask a Question