note 10457 modified in ref.oracle by irchtml
| From: | irchtml@php.net | Date: | Tue, 17 Feb 2004 14:33:33 +0000 |
| Subject: | note 10457 modified in ref.oracle by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65301@lists.php.net to get a copy of this message | ||
Here is a code sample that I used on NT 4.0 running Apache/Oracle 8.1.6/PHP 4.0 : I used it to
connect to the sample scott-tiger schema EMP table. It is pretty much a hack, but I hope it helps
you.
<?php
putenv('ORACLE_SID=DMEARLS.WORLD');
putenv('ORACLE_HOME=d:\oracle\ora81');
putenv('TNS_ADMIN=d:\oracle\ora81\network\admin');
$foo=exec("echo %ORACLE_SID%");
echo $foo;
//Set("ORACLE_SID=DMEARLS.WORLD");
//Set("ORACLE_HOME=D:\oracle\isuites");
//$db = "dmearls.world";
// create connection
// $connection = ora_logon("scott","tiger")
$connection = OCILogon("scott","tiger","dmearls.world")
or die("Couldn't logon to database.");
// create SQL statement
$sql = "SELECT ENAME, SAL
FROM EMP
ORDER BY SAL";
echo "<br>";
echo $connection;
echo "<br>";
echo $sql;
echo "<br>";
// parse SQL statement
$sql_statement = OCIParse($connection,$sql)
or die("Couldn't parse statement.");
echo $sql_statement;
// execute SQL query
OCIExecute($sql_statement)
or die("Couldn't execute statement.");
// get number of columns for use later
$num_columns = OCINumCols($sql_statement);
echo "<br>";
echo $num_columns;
// start results formatting
echo "<TABLE BORDER=1>";
echo "<TR>
<TH>Name</TH>
<TH>Salary</TH>
</TR>
";
// format results by row
while (OCIFetch($sql_statement)) {
echo "<TR>";
for ($i = 1; $i < $num_columns; $i++) {
$column_value1 = OCIResult($sql_statement,$i);
$column_value2 = OCIResult($sql_statement,$i+1);
//echo $i;
echo "<TD>$column_value1</TD>";
echo "<TD>$column_value2</TD>";
}
echo "</TR>";
}
echo "</TABLE>";
// free resources and close connection
OCIFreeStatement($sql_statement);
OCILogoff($connection);
?>
--was--
Here is a code sample that I used on NT 4.0 running Apache/Oracle 8.1.6/PHP 4.0 : I used it to
connect to the sample scott-tiger schema EMP table. It is pretty much a hack, but I hope it helps
you.
<?php
putenv('ORACLE_SID=DMEARLS.WORLD');
putenv('ORACLE_HOME=d:\oracle\ora81');
putenv('TNS_ADMIN=d:\oracle\ora81\network\admin');
$foo=exec("echo %ORACLE_SID%");
echo $foo;
//Set("ORACLE_SID=DMEARLS.WORLD");
//Set("ORACLE_HOME=D:\oracle\isuites");
//$db = "dmearls.world";
// create connection
// $connection = ora_logon("scott","tiger")
$connection = OCILogon("scott","tiger","dmearls.world")
or die("Couldn't logon to database.");
// create SQL statement
$sql = "SELECT ENAME, SAL
FROM EMP
ORDER BY SAL";
echo "<br>";
echo $connection;
echo "<br>";
echo $sql;
echo "<br>";
// parse SQL statement
$sql_statement = OCIParse($connection,$sql)
or die("Couldn't parse statement.");
echo $sql_statement;
// execute SQL query
OCIExecute($sql_statement)
or die("Couldn't execute statement.");
// get number of columns for use later
$num_columns = OCINumCols($sql_statement);
echo "<br>";
echo $num_columns;
// start results formatting
echo "<TABLE BORDER=1>";
echo "<TR>
<TH>Name</TH>
<TH>Salary</TH>
</TR>
";
// format results by row
while (OCIFetch($sql_statement)) {
echo "<TR>";
for ($i = 1; $i < $num_columns; $i++) {
$column_value1 = OCIResult($sql_statement,$i);
$column_value2 = OCIResult($sql_statement,$i+1);
//echo $i;
echo "<TD>$column_value1</TD>";
echo "<TD>$column_value2</TD>";
}
echo "</TR>";
}
echo "</TABLE>";
// free resources and close connection
OCIFreeStatement($sql_statement);
OCILogoff($connection);
?>
http://www.php.net/manual/en/ref.oracle.php