[lug] php/oracle question (somewhat OT)

Chip Atkinson chip at rmpg.org
Mon Jun 17 12:22:38 MDT 2002


Posting the code is a good idea, I'll do that below.  I've used php/mysql
before and really liked it, probably due to the ease of use. :-)
The php code below using oracle have been giving me fits though.

TIA,

Chip

$conn = ora_logon("user", "password"); // Not the real values here of course

$query = "SELECT
            acct acct, name, docdt, docnm, ROWID
          FROM
            onlstm_cont c
          WHERE
            acct=1111 and cu='abcd'
          ORDER BY
            name, acct,ssn, docdt, docnm";

/* This one seems to work if there is only one row.
 * If more than one row, we get an oracle error, 1422,
 * exact fetch returns more than requested number of rows.
 */
$query2 = "declare tmp char(40);
           begin
             select ufsnm into :tmp from onlstm_cont
             where acct=1111 and cu='abcd';
          end;";

$cursor = ora_open ($conn);
echo "<br>Cursor: $cursor, Conn: $conn<br>";
$defer = 0;
if (ora_parse ($cursor, $query, $defer))
{
  echo ("<br> Successful parse<br>\n");
}
else
{
  echo ora_error ($conn);
}

$phpacct = "undefinedvalue";
$len = 40;
if (ora_bind ($cursor, "phpacct", ":tmp", $len))
{
  echo ("<br> Successful bind<br>\n");
}
else
{
  echo ("<br>Bind ERROR<br>\n");
  echo ora_error ($conn);
  echo ("<br>cursor errorcode: \n");
  echo ora_errorcode ($cursor);
  echo ("<br>Connection errorcode: \n");
  echo ora_errorcode ($conn);
  echo ("<br>\n");
}

if (ora_exec ($cursor))
{
  echo ("<br> Successful exec<br>\n");
}
else
{
  echo "ora_exec error:<br>\n";
  echo ora_error ($conn);
  echo ("<br>cursor errorcode: \n");
  echo ora_errorcode ($cursor);
  echo ("<br>Connection errorcode: \n");
  echo ora_errorcode ($conn);
  echo ("<br>\n");
}

if (ora_fetch ($cursor))
{
  echo ("<br> Successful ora_fetch<br>\n");
}
else
{
  echo "ora_fetch error:<br>\n";
  echo ora_error ($conn);
  echo ("<br>cursor errorcode: \n");
  echo ora_errorcode ($cursor);
  echo ("<br>Connection errorcode: \n");
  echo ora_errorcode ($conn);
  echo ("<br>\n");
}
echo "<br>Phpacct: $phpacct<br>\n";

ora_logoff ($conn);


On Mon, 17 Jun 2002, Barney Treadway wrote:

> I can send you some snippets on php to mysql if that would help, or try
> posting your code here for quick "look see". PHP manual doesn't help much on
> the while fetch_array side of things.
>
> Barney
>
> ----- Original Message -----
> From: "Chip Atkinson" <chip at rmpg.org>
> To: <lug at lug.boulder.co.us>
> Sent: Monday, June 17, 2002 11:46 AM
> Subject: [lug] php/oracle question (somewhat OT)
>
>
> > Greetings,
> >
> > I'm trying to make some sql queries from within php to an oracle 7
> > database and am having little if any luck.  The most success I've had is
> > getting one row back.  If there are more rows than one returned, I get
> > oracle errors.  I've been poring over the php online manual, and have not
> > gotten anywhere, even using the examples from both users and the manual.
> >
> > Is there anyone that can send me a bit of example code from the actual
> > query to the fetching of the data?
> >
> > Thanks in advance.
> >
> > Chip
> >
> > _______________________________________________
> > Web Page:  http://lug.boulder.co.us
> > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> > Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> >
>
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
>




More information about the LUG mailing list