|
Re: Unloading from Oracle in PHP [message #661774 is a reply to message #661773] |
Fri, 31 March 2017 14:49 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Here's a simple example of a PHP script to load the standard EMP table into your page:
<HTML>
<HEAD>
<TITLE>EMP table</TITLE>
<META NAME="Description" CONTENT="EMP table content.">
</HEAD>
<BODY BGCOLOR="#CCDDFF">
<?php
if ($Con = oci_connect("$Account","$Password","$Base")) {
$Query = "select empno, ename, job, mgr, hiredate, sal, comm, deptno from emp order by 1";
print "</TABLE>\n";
print "<TR>\n";
print " <TD ALIGN=\"CENTER\"><FONT FACE=\"Arial\" SIZE=\"2\"><B>Empno</B></FONT></TD>\n";
print " <TD ALIGN=\"CENTER\"><FONT FACE=\"Arial\" SIZE=\"2\"><B>Ename</B></FONT></TD>\n";
print " <TD ALIGN=\"CENTER\"><FONT FACE=\"Arial\" SIZE=\"2\"><B>Job</B></FONT></TD>\n";
print " <TD ALIGN=\"CENTER\"><FONT FACE=\"Arial\" SIZE=\"2\"><B>Mgr</B></FONT></TD>\n";
print " <TD ALIGN=\"CENTER\"><FONT FACE=\"Arial\" SIZE=\"2\"><B>Hiredate</B></FONT></TD>\n";
print " <TD ALIGN=\"CENTER\"><FONT FACE=\"Arial\" SIZE=\"2\"><B>Sal</B></FONT></TD>\n";
print " <TD ALIGN=\"CENTER\"><FONT FACE=\"Arial\" SIZE=\"2\"><B>Comm</B></FONT></TD>\n";
print " <TD ALIGN=\"CENTER\"><FONT FACE=\"Arial\" SIZE=\"2\"><B>Deptno</B></FONT></TD>\n";
print "</TR>\n";
$stmt = OCIParse($Con, $Query);
$r = OCIExecute($stmt);
while (OCIFetch($stmt)) {
$empno = OCIResult($stmt, 1);
$ename = OCIResult($stmt, 2);
$job = OCIResult($stmt, 3);
$mgr = OCIResult($stmt, 4);
$hiredate = OCIResult($stmt, 5);
$sal = OCIResult($stmt, 6);
$comm = OCIResult($stmt, 7);
$deptno = OCIResult($stmt, 8);
print "<TR>\n";
print " <TD ALIGN=\"RIGHT\"><FONT FACE=\"Courier New\" SIZE=\"2\"> $empno </FONT></TD>\n";
print " <TD ALIGN=\"LEFT\"><FONT FACE=\"Courier New\" SIZE=\"2\"> $ename </FONT></TD>\n";
print " <TD ALIGN=\"LEFT\"><FONT FACE=\"Courier New\" SIZE=\"2\"> $job </FONT></TD>\n";
print " <TD ALIGN=\"RIGHT\"><FONT FACE=\"Courier New\" SIZE=\"2\"> $mgr </FONT></TD>\n";
print " <TD ALIGN=\"LEFT\"><FONT FACE=\"Courier New\" SIZE=\"2\"> $hiredate </FONT></TD>\n";
print " <TD ALIGN=\"RIGHT\"><FONT FACE=\"Courier New\" SIZE=\"2\"> $sal </FONT></TD>\n";
print " <TD ALIGN=\"RIGHT\"><FONT FACE=\"Courier New\" SIZE=\"2\"> $comm </FONT></TD>\n";
print " <TD ALIGN=\"RIGHT\"><FONT FACE=\"Courier New\" SIZE=\"2\"> $deptno </FONT></TD>\n";
print "</TR>\n";
}
print "</TABLE>\n";
} else {
$errmsg = oci_error();
print 'Oracle connect error '. $errmsg['message'];
}
?>
</BODY>
</HTML>
$Account, $Password and $Base are variables that are assumed to have been previously set (in another page).
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Unloading from Oracle in PHP [message #661944 is a reply to message #661879] |
Thu, 06 April 2017 13:54 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
As far as I understand the problem, your current SELECT statement has to be modified in one of two ways. The first one is to hard-code those values using DECODE or CASE, such as
select
decode(oil, 2, 'AZS brook', 3, 'AZS willi') using_decode,
case when oil = 2 then 'AZS brook'
when oil = 3 then 'AZS willi'
end using_case
...
Or, if "oil" description is (and yes, it probably should be) stored in another table, join these two tables, such as
select a.fio_client, a.city, b.oil_description
from current_table a, another_table b
where a.oil = b.oil
|
|
|