I have a web site implemented in php 4.x and MySQL 3.22.x running on linux and have local test sites running on W2K and linux. As an exercise, I have implemented a database wrapper for MySQL, MSSQL Server 2000 and Orcacle9i and will be adding one for Sybase shortly.
I have a question on the Oracle implementation with code fragments below to illustrate. In MySQL and SQL Server I can retrieve data from a row by Column Name. So far I haven't been able to get that to work. In the code below I can retrieve the 'Count' column by $Count = $QueryData [ "Count" ]; but for Oracle that doesn't work and I have to use $Count = $QueryData [ 0 ];. Calling ora_fetch_into using the ORA_FETCHINTO_ASSOC
flag doesn't work. When I use it, I can't even retrieve the column value by number.
Does anyone have any suggestions why the ORA_FETCHINTO_ASSOC flag doesn't work or how to retrieve column data by Column Name.
function GetPageCount ( $MiddlePanelFile )
{
global $Server;
// Open the DB
$link = ConnectToDatabase ( );
// Get the count for the page
$query = "select Count from PAGECOUNTS where PageName = '$MiddlePanelFile' and Server = '$Server'";
$result = dbQuery ( array ( $query, $link ) );
if ( !$result )
return false;
else
{
if ( DB_ORACLE9i )
{
array ( $rows );
$QueryData = dbFetchRow ( array ( $link, $rows ) ); // Works
//$QueryData = dbFetchRow ( array ( $link, $rows, DB_GETMODE_ASSOC ) ); // Doesn't Work
//$QueryData = dbFetchRow ( array ( $link, $rows, DB_GETMODE_NULL ) ); // Works
$Count = $QueryData [ 0 ];
}
else
{
// MySQL and SQL Server 2000
$QueryData = dbFetchRow ( array ( $result, DB_GETMODE_BOTH ) );
$Count = $QueryData [ "Count" ];
}
if ( $Count )
{
// add one to the page count
$query = "update PAGECOUNTS set Count = Count + 1 where PageName = '$MiddlePanelFile' and Server = '$Server'";
$result = dbQuery ( array ( $query, $link ) );
$Count++;
}
else
{
// record doesn't exist, add it
$query = "insert into PAGECOUNTS VALUES ( '$MiddlePanelFile', '$Server', 1051 )";
$result = dbQuery ( array ( $query, $link ) );
$Count = 1051;
}
}
return $Count;
}
// Oracle9i dbFetchRow
function dbFetchRow ( $args = array ( ) )
{
switch ( $args [ 2 ] )
{
case DB_GETMODE_ASSOC:
$cols = @ora_fetch_into ( $args [ 0 ], $rows, ORA_FETCHINTO_ASSOC );
break;
case DB_GETMODE_NULL:
$cols = @ora_fetch_into ( $args [ 0 ], $rows, ORA_FETCHINTO_NULLS );
break;
default:
$cols = @ora_fetch_into ( $args [ 0 ], $rows );
break;
}
if ( $cols )
return $rows;
return false;
}
// MySQL FetchRow
function dbFetchRow ( $args = array ( ) )
{
if ( $args [ 1 ] == DB_GETMODE_ASSOC )
{
@mysql_fetch_array ( $args [ 0 ], MYSQL_ASSOC );
}
elseif ( $args [ 1 ] == DB_GETMODE_NUM )
{
return @mysql_fetch_array ( $args [ 0 ], MYSQL_NUM );
}
return @mysql_fetch_array ( $args [ 0 ] ); // MYSQL_BOTH
}
// SQL Server 2000 dbFetchRow
function dbFetchRow ( $args = array ( ) )
{
return @mssql_fetch_array ( $args [ 0 ] );
}