Paradox File Access
- Введение
- Установка и настройка
- Предопределенные константы
- Paradox Функции
- px_close — Closes a paradox database
- px_create_fp — Create a new paradox database
- px_date2string — Converts a date into a string.
- px_delete_record — Deletes record from paradox database
- px_delete — Deletes resource of paradox database
- px_get_field — Returns the specification of a single field
- px_get_info — Return lots of information about a paradox file
- px_get_parameter — Gets a parameter
- px_get_record — Returns record of paradox database
- px_get_schema — Returns the database schema
- px_get_value — Gets a value
- px_insert_record — Inserts record into paradox database
- px_new — Create a new paradox object
- px_numfields — Returns number of fields in a database
- px_numrecords — Returns number of records in a database
- px_open_fp — Open paradox database
- px_put_record — Stores record into paradox database
- px_retrieve_record — Returns record of paradox database
- px_set_blob_file — Sets the file where blobs are read from
- px_set_parameter — Sets a parameter
- px_set_tablename — Sets the name of a table (deprecated)
- px_set_targetencoding — Sets the encoding for character fields (deprecated)
- px_set_value — Sets a value
- px_timestamp2string — Converts the timestamp into a string.
- px_update_record — Updates record in paradox database
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- CUBRID
- DB++
- dBase
- filePro
- Firebird/InterBase
- FrontBase
- IBM DB2, Cloudscape and Apache Derby
- Informix
- Ingres DBMS, EDBC, and Enterprise Access Gateways
- MaxDB
- MongoDB
- MongoDB
- mSQL
- Microsoft SQL Server
- MySQL Drivers and Plugins
- Oracle OCI8
- Paradox File Access
- PostgreSQL
- SQLite
- SQLite3
- Microsoft SQL Server Driver for PHP
- Sybase
- tokyo_tyrant
Коментарии
<?php
/*
Implement class to use paradox functions
*/
class cParadox
{
//members
var $m_pxdoc = NULL;
var $m_fp = NULL;
var $m_rs = NULL;
var $m_default_field_value = "";
var $m_use_field_slashes = false;
var $m_use_field_trim = false;
function Open($filename)
{
$this->m_pxdoc = px_new();
if( !$this->m_pxdoc)
{
die ("cParadox Error: px_new() failed.");
}
$this->m_fp = fopen($filename, "r");
if(!$this->m_fp)
{
px_delete($this->m_pxdoc);
die ("cParadox Error: fopen failed.Filename:$filename");
}
if(!px_open_fp($this->m_pxdoc ,$this->m_fp) )
{
px_delete($this->m_pxdoc);
fclose( $this->m_fp );
die ("cParadox Erro: px_open_fp failed.");
}
return true;
}
function Close()
{
if ( $this->m_pxdoc )
{
px_close($this->m_pxdoc);
px_delete($this->m_pxdoc);
}
if( $this->m_fp )
{
fclose( $this->m_fp );
}
}
function GetNumRecords()
{
return px_numrecords($this->m_pxdoc);
}
function GetRecord($rec)
{
$this->m_rs = px_get_record($this->m_pxdoc ,$rec ,PX_KEYTOUPPER);
return $this->m_rs;
}
function GetField($field ,$type=0, $format=0)
{
if ( !$this->m_rs )
{
return false;
}
$value = isset($this->m_rs[$field])? $this->m_rs[$field] : "";
if ( $this->m_use_field_slashes )
{
$value = addslashes($value);
}
if ( $this->m_use_field_trim )
{
$value = trim($value);
}
return $value;
}
};
usage example:
error_reporting(E_ERROR);
require_once("cparadox.inc");
$pdx = new cParadox();
$pdx->m_default_field_value = "?";//" ";
if ( $pdx->Open("USERS.DB") )
{
$tot_rec = $pdx->GetNumRecords();
if ( $tot_rec )
{
echo "<table border=1>\n";
for($rec=0; $rec<$tot_rec; $rec++)
{
$pdx->GetRecord($rec);
echo "<tr>";
echo "<td>" . $rec;
echo "<td>" . $pdx->GetField(CODE);
echo "<td>" . $pdx->GetField(NAME);
}
}
$pdx->Close();
}
?>
A bit updated version of wilson's class
<?php
class Paradox {
var $doc = NULL;
var $file = NULL;
var $row = NULL;
var $field_default_value = "";
var $field_slashes = false;
var $field_trim = false;
function Open($filename) {
$this->doc = px_new();
if (!$this->doc) {
die("Paradox Error: px_new() failed.");
}
$this->file = fopen($filename, "r");
if (!$this->file) {
px_delete($this->doc);
die("Paradox Error: fopen failed. Filename:$filename");
}
if (!px_open_fp($this->doc, $this->file)) {
px_delete($this->doc);
fclose($this->file);
die("Paradox Erro: px_open_fp failed.");
}
return true;
}
function Close() {
if ($this->doc) {
px_close($this->doc);
px_delete($this->doc);
}
if ($this->file) {
fclose($this->file);
}
}
function GetNumRows() {
return px_numrecords($this->doc);
}
function GetRow($id) {
try {
$this->row = px_get_record($this->doc, $id);
throw new Exception('no record');
} catch (Exception $e) {
return "Exception: " . $e->getMessage() . "\n";
}
return $this->row;
}
function GetRows($num = 0) {
if (function_exists(px_retrieve_record)) {
return px_retrieve_record($this->doc, $num);
} else {
return "Unsupported function (px_retrieve_record) in paradox ext.";
}
}
function GetSchema() {
return px_get_schema($this->doc);
}
function GetInfo() {
return px_get_info($this->doc);
}
function GetStringfromDate($date, $format = "d.m.Y") {
return px_date2string($this->doc, $date, $format);
}
function GetStringfromTimestamp($date, $format = "d.m.Y H:i:s") {
return px_timestamp2string($this->doc, $date, $format);
}
function GetField($field, $trim = 0, $slash = 0) {
if (!$this->row) {
return false;
}
$value = isset($this->row[$field]) ? $this->row[$field] : $this->field_default_value;
if ($this->field_slashes or $slash) {
$value = addslashes($value);
}
if ($this->field_trim or $trim) {
$value = trim($value);
}
return $value;
}
function GetFieldInfo($id = 0) {
return px_get_field($this->doc, $id);
}
}
?>