From: pnixon Date: Tue, 15 Mar 2005 17:01:43 +0000 (+0000) Subject: A first stab at using DBX for database abstraction. Works with Postgres currently. X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=ea2c95a236e244f85b4468f61c0c54b284db74f0;p=freeradius-dialup-admin.git A first stab at using DBX for database abstraction. Works with Postgres currently. --- diff --git a/lib/sql/drivers/dbx/functions.php3 b/lib/sql/drivers/dbx/functions.php3 new file mode 100644 index 0000000..655aedd --- /dev/null +++ b/lib/sql/drivers/dbx/functions.php3 @@ -0,0 +1,134 @@ +DEBUG(SQL,PG DRIVER): Query: $query
\n"; + } + return @dbx_query($link,$query); +} + +function da_sql_num_rows($result,$config) +{ + if ($config[sql_debug] == 'true') + print "DEBUG(SQL,PG DRIVER): Query Result: Num rows:: " . $result->rows . "
\n"; + return $result->rows; +} + +$dbx_global_record_counter = array() ; +function da_sql_fetch_array($result,$config) +{ + + global $dbx_global_record_counter; + if (!$dbx_global_record_counter[$result->handle]){ + $dbx_global_record_counter[$result->handle] = 0; + } + + if ($dbx_global_record_counter[$result->handle] <= $result->rows - 1 ){ + return $result->data[$dbx_global_record_counter[$result->handle]++]; + } elseif ($dbx_global_record_counter[$result->handle] > $result->rows - 1 ) { + $dbx_global_record_counter[$result->handle]++; + return NULL; + } else { + $dbx_global_record_counter[$result->handle]++; + return FALSE; + } +} + +function da_sql_affected_rows($link,$result,$config) +{ + // FIXME: This function is still Postgres specific. + if ($config[sql_debug] == 'true') + print "DEBUG(SQL,PG DRIVER): Query Result: Affected rows:: " . @pg_cmdtuples($result->handle) . "
\n"; + return @pg_cmdtuples($result->handle); +} + +function da_sql_list_fields($table,$link,$config) +{ + $res = @dbx_query($link,"SELECT * FROM ".$table." LIMIT 1 ;"); + if ($res){ + $fields[num] = $res->cols; + } + $res = @dbx_query($link,"SELECT * FROM ".$table." LIMIT 1 ;"); + if ($res) + $fields[res] = $res->info[name]; + else + return NULL; + + return $fields; +} + +function da_sql_num_fields($fields,$config) +{ + if ($fields) + return $fields[num]; +} + +function da_sql_field_name($fields,$num,$config) +{ + if ($fields) + return $fields[res][$num]; +} + +function da_sql_error($link,$config) +{ + return dbx_error($link); +} +?>