note 42493 deleted from ref.com by tomsommer
| From: | tomsommer@php.net | Date: | Tue, 18 May 2004 22:30:11 +0000 |
| Subject: | note 42493 deleted from ref.com by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69801@lists.php.net to get a copy of this message | ||
Note Submitter: angelo [at] mandato <dot> com
----
Useful PHP functions I created (similar to other standard PHP database functions) for working with
an AOD datasource:
<?php
// aod.inc.php
$AOD_NUM = 1;
$AOD_ASSOC = 2;
$AOD_BOTH = 3;
function aod_connect( $dsn )
{
$link = new COM("ADODB.Connection");
$link->Open($dsn);
return $link;
}
function aod_close( $link )
{
$link->Close();
}
function aod_num_fields( $rs )
{
return $rs->Fields->Count;
}
function aod_error($link)
{
return $link->Errors[$link->Errors->Count-1]->Number;
}
function aod_errormsg($link)
{
return $link->Errors[$link->Errors->Count-1]->Description;
}
function aod_fetch_array( $rs, $result_type, $row_number = -1 )
{
global $AOD_NUM, $AOD_ASSOC, $AOD_BOTH;
if( $row_number > -1 ) // Defined in adoint.h - adBookmarkFirst = 1
$rs->Move( $row_number, 1 );
if( $rs->EOF )
return false;
$ToReturn = array();
for( $x = 0; $x < aod_num_fields($rs); $x++ )
{
if( $result_type == $AOD_NUM || $result_type == $AOD_BOTH )
$ToReturn[ $x ] = $rs->Fields[$x]->Value;
if( $result_type == $AOD_ASSOC || $result_type == $AOD_BOTH )
$ToReturn[ $rs->Fields[$x]->Name ] = $rs->Fields[$x]->Value;
}
$rs->MoveNext();
return $ToReturn;
}
function aod_num_rows( $rs )
{
return $rs->RecordCount;
}
function aod_free_result( $rs )
{
$rs->Close();
}
function aod_query( $link, $query )
{
return $link->Execute($query);
}
function aod_fetch_assoc( $rs, $row_number = -1 )
{
global $AOD_ASSOC;
return aod_fetch_array( $rs, $AOD_ASSOC, $row_number);
}
function aod_fetch_row( $rs, $row_number = -1 )
{
global $AOD_NUM;
return aod_fetch_array( $rs, $AOD_NUM, $row_number);
}
// Extra functions:
function aod_field_len( $rs, $field_number )
{
return $rs->Fields[$field_number]->Precision;
}
function aod_field_name( $rs, $field_number )
{
return $rs->Fields[$field_number]->Name;
}
function aod_field_scale( $rs, $field_number )
{
return $rs->Fields[$field_number]->NumericScale;
}
function aod_field_type( $rs, $field_number )
{
return $rs->Fields[$field_number]->Type;
}
?>