[phplib] Accessing fields with reserved names etc. From:  <email protected>
Date: 11/17/00

11/17/2000 03:14 PM
(subscript: Jesper Frank Nemholt <email protected>)
Hi!

I've just implemented PHPLib in a application that used to be hardcoded to
MySQL.
The goal was to make it compatible with at least Oracle & MySQL, since it's
going to run on Oracle8 in near future.

I ran in to a few problems, mostly related to the different way Oracle handles
various stuff and missing features in PHPLib or Oracle compared to normal MySQL
calls in PHP.
It's the first time I use PHPLib, so many of my problems are probably in the FAQ
category.

First the problem I couldn't solve :

All my tables start with a field/column named DATE.
This is a reserved word in Oracle, and when doing a SELECT, I have to write
"DATE" to make it work.
Problem is, that when I later try to access the field using :

     q->f("DATE")

...it doesn't work. I've tried q->f('"DATE'") and other variants, but none of
them works.
Is there a solution for this ?

Secondly, according to the documentation of PHPLib, table_names() should be
implemented in db_oci8.inc and db_oracle.inc, but it somehow doesn't work for
me.
Can anyone verify that it actually works on Oracle8 ?
I came up with this alternative solution, but I'd prefer to use a standard
PHPLib call instead :

if ($q->type == "oci8")
{
     $tmp = "'" . $ORACLE_SID . "'";
     $query = sprintf("SELECT table_name FROM all_tables WHERE owner=$tmp");
     $q->query($query);
     $result = array();
     while ($q->next_record())
     {
          array_push($result, strtolower($q->f("table_name")));
     }
}
else
{
     $result = $q->table_names();
}

At last, I needed something like MySQLs DESCRIBE table and ended up with this
solution, which is just as ugly as my other solution :

if ($q->type == "oci8")
{
     $SID = "'" . $ORACLE_SID . "'";
     $tb_name = "'" . strtoupper($HTTP_POST_VARS["table_table"]) . "'";
     $query = sprintf("SELECT column_name,data_type FROM all_tab_columns WHERE
owner=$SID AND table_name=$tb_name");
}
elseif ($q->type == "mysql")
{
     $query = sprintf("DESCRIBE $table");
}
else
{
     echo "Unsupported database<BR>\n";
}

Regarding $q->type; isn't it supposed to be set to the active database type
autmagically. In my setup it's empty allways, so I had to set it by hand.

If anyone has better ways for the solutions above, I'd like to hear.

Please CC to my mail address.

/Jesper

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>