For use PHPv5 functions in PHPv4 i use simple script:
<?php
$funcs=array(
'oci_connect'=>'OCILogon',
'oci_parse'=>'OCIParse',
'oci_execute'=>'OCIExecute',
'oci_fetch'=>'OCIFetch',
'oci_num_fields'=>'OCINumCols',
'oci_field_name'=>'OCIColumnName',
'oci_result'=>'OCIResult',
'oci_free_statement'=>'OCIFreeStatement',
);
// yoy can add yours pairs of funcs.
foreach ($funcs as $k=>$v)
{
if (!function_exists($k))
{
$arg_string='$p0';
for ($i=1;$i<20;$i++) {
$arg_string.=',$p'.$i;
}
eval ('function '.$k.' () {
list('.$arg_string.')=func_get_args();
return '.$v.'('.$arg_string.');
}
');
}
}
?>
simple, but it work. :-)
CV. Oracle 8 Funktionen
Diese Funktionen gestatten den Zugriff auf Oracle7 und Oracle8 Datenbanken. Es wird hierbei das Oracle8 Call-Interface (OCI8) verwendet, welches installierte Oracle8 Client Bibliotheken (Libraries) benötigt.
Diese Schnittstelle ist flexibler als die Standard Oracle Funktionen. Es unterstützt Binding von localen und globalen PHP Variablen an Oracle Platzhalter und hat volle LOB,FILE und ROWID Unterstützung und gestattet dem Benutzer die Verwendung von Variablendefines.
Vor der Benutzung dieser Erweiterung sollten Sie sicherstellen die folgenden Umgebungsvariablen für den Webserveruser VOR dem Start des Webservers gesetzt zu haben.
- ORACLE_HOME
- ORACLE_SID
- LD_PRELOAD
- LD_LIBRARY_PATH
- NLS_LANG
- ORA_NLS33
Nachdem Sie die Umgebungsvariablen festgelegt haben, stellen Sie sicher, das die Dateien im ORACLE_HOME/network/admin für den Webserver lesbar sind.
Wenn der Webserver abstürzt nach dem Start, oder nicht startet: Überprüfen Sie, ob der Apache gegen -lpthread gelink ist:
# ldd /www/apache/bin/httpd libpthread.so.0 => /lib/libpthread.so.0 (0x4001c000) libm.so.6 => /lib/libm.so.6 (0x4002f000) libcrypt.so.1 => /lib/libcrypt.so.1 (0x4004c000) libdl.so.2 => /lib/libdl.so.2 (0x4007a000) libc.so.6 => /lib/libc.so.6 (0x4007e000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)Wenn libpthread hier nicht gelistet ist, dann muss der Webserver neu übersetzt werden:
# cd /usr/src/apache_1.3.xx # make clean # LIBS=-lpthread ./config.status # make # make install
Beispiel 1334. OCI Hinweise
<?php |
Man kann auf Stored Procedures auf einfache Weise zugreifen.
Beispiel 1335. Stored Procedures benutzen
<?php |
Inhaltsverzeichnis
- OCI-Collection->append — Appends element to the collection
- OCI-Collection->assign — Assigns a value to the collection from another existing collection
- OCI-Collection->assignElem — Assigns a value to the element of the collection
- OCI-Collection->free — Frees the resources associated with the collection object
- OCI-Collection->getElem — Returns value of the element
- OCI-Collection->max — Returns the maximum number of elements in the collection
- OCI-Collection->size — Returns size of the collection
- OCI-Collection->trim — Trims elements from the end of the collection
- OCI-Lob->append — Appends data from the large object to another large object
- OCI-Lob->close — Closes LOB descriptor
- OCI-Lob->eof — Tests for end-of-file on a large object's descriptor
- OCI-Lob->erase — Erases a specified portion of the internal LOB data
- OCI-Lob->export — Exports LOB's contents to a file
- OCI-Lob->flush — Flushes/writes buffer of the LOB to the server
- OCI-Lob->free — Frees resources associated with the LOB descriptor
- OCI-Lob->getBuffering — Returns current state of buffering for the large object
- OCI-Lob->import — Imports file data to the LOB
- OCI-Lob->load — Returns large object's contents
- OCI-Lob->read — Reads part of the large object
- OCI-Lob->rewind — Moves the internal pointer to the beginning of the large object
- OCI-Lob->save — Saves data to the large object
- OCI-Lob->saveFile — Alias von oci_lob_import()
- OCI-Lob->seek — Sets the internal pointer of the large object
- OCI-Lob->setBuffering — Changes current state of buffering for the large object
- OCI-Lob->size — Returns size of large object
- OCI-Lob->tell — Returns current position of internal pointer of large object
- OCI-Lob->truncate — Truncates large object
- OCI-Lob->write — Writes data to the large object
- OCI-Lob->writeTemporary — Writes temporary large object
- OCI-Lob->writeToFile — Alias von oci_lob_export()
- oci_bind_array_by_name — Bindet ein PHP-Array namentlich an ein Oracle-PL/SQL-Array
- oci_bind_by_name — Bindet eine PHP-Variable an einen Oracle Platzhalter
- oci_cancel — Bricht das Lesen eines Zeigers ab.
- oci_close — Schliesst eine Oracle-Verbindung
- oci_commit — Commits outstanding statements
- oci_connect — Establishes a connection to the Oracle server
- oci_define_by_name — Uses a PHP variable for the define-step during a SELECT
- oci_error — Liefert den letzten Fehler
- oci_execute — Executes a statement
- oci_fetch_all — Fetches all rows of result data into an array
- oci_fetch_array — Returns the next row from the result data as an associative or numeric array, or both
- oci_fetch_assoc — Returns the next row from the result data as an associative array
- oci_fetch_object — Returns the next row from the result data as an object
- oci_fetch_row — Returns the next row from the result data as a numeric array
- oci_fetch — Fetches the next row into result-buffer
- oci_field_is_null — Checks if the field is NULL
- oci_field_name — Returns the name of a field from the statement
- oci_field_precision — Tell the precision of a field
- oci_field_scale — Tell the scale of the field
- oci_field_size — Returns field's size
- oci_field_type_raw — Tell the raw Oracle data type of the field
- oci_field_type — Returns field's data type
- oci_free_statement — Gibt alle verknüpften Ressourcen eines Statements oder Zeigers frei.
- oci_internal_debug — Enables or disables internal debug output
- oci_lob_copy — Copies large object
- oci_lob_is_equal — Compares two LOB/FILE locators for equality
- oci_new_collection — Allocates new collection object
- oci_new_connect — Establishes a new connection to the Oracle server
- oci_new_cursor — Allocates and returns a new cursor (statement handle)
- oci_new_descriptor — Initializes a new empty LOB or FILE descriptor
- oci_num_fields — Returns the number of result columns in a statement
- oci_num_rows — Returns number of rows affected during statement execution
- oci_parse — Prepares Oracle statement for execution
- oci_password_change — Changes password of Oracle's user
- oci_pconnect — Connect to an Oracle database using a persistent connection
- oci_result — Returns field's value from the fetched row
- oci_rollback — Rolls back outstanding transaction
- oci_server_version — Returns server version
- oci_set_prefetch — Sets number of rows to be prefetched
- oci_statement_type — Returns the type of an OCI statement
- ocibindbyname — Bindet eine PHP-Variable an einen Oracle Platzhalter
- ocicancel — bricht das lesen von einem cursor ab
- ocicloselob — Alias von OCI-Lob->close
- ocicollappend — Alias von OCI-Collection->append
- ocicollassign — Kommt noch.
- ocicollassignelem — Kommt noch.
- ocicollgetelem — Kommt noch.
- ocicollmax — Kommt noch.
- ocicollsize — Kommt noch.
- ocicolltrim — Kommt noch.
- ocicolumnisnull — Testet eine Spalte ob deren Inhalt NULL ist
- ocicolumnname — Liefert den Namen der Spalte zurück.
- ocicolumnprecision — Kommt noch.
- ocicolumnscale — Kommt noch.
- ocicolumnsize — Gibt die Grösse einer Spalte zurück
- ocicolumntype — Liefert den Datentyp einer Spalte zurück.
- ocicolumntyperaw — Kommt noch.
- ocicommit — Committet eine ausstehende Transaktion.
- ocidefinebyname — Definiert eine PHP Variable als Platzhalter für die Werte eines SELECTs
- ocierror — Gibt den letzten Fehler von stmt|conn|global zurück oder FALSE, wenn kein Fehler aufgetreten ist.
- ociexecute — führt ein Statement aus.
- ocifetch — Fetcht die nächste Ergebniszeile in den Ergebnispuffer
- ocifetchinto — Fetcht die nächste Zeile eines Ergebnisses in ein Array
- ocifetchstatement — Fetcht die Ergebnisse in ein Array
- ocifreecollection — Kommt noch.
- ocifreecursor — Gibt alle mit dem cursor verbundenen Ressourcen frei.
- ocifreedesc — Alias von OCI-Lob->free
- ocifreestatement — Gibt alle mit dem Statement verbundenen Ressourcen frei.
- ociinternaldebug — Aktiviert oder deaktiviert die interne Debugausgabe. Die Voreinstellung ist deaktiviert.
- ociloadlob — Kommt noch.
- ocilogoff — Schliesst eine Datenbankverbindung zu Oracle
- ocilogon — Baut eine OCI-Verbindung auf
- ocinewcollection — Kommt noch.
- ocinewcursor — return a new cursor (Statement-Handle) - use this to bind ref-cursors!
- ocinewdescriptor — Initialize a new empty descriptor LOB/FILE (LOB is default)
- ocinlogon — Logt sich in die Oracle Datenbank ein und erzeugt dabei eine neue Oracle Session.
- ocinumcols — Gibt die Anzahl der Spalten in einem Statement zurück
- ociparse — Analysiert eine Abfrage und gibt eine Anweisung zurück.
- ociplogon — Logt sich persistent in die Oracle Datenbank ein und erzeugt eine neue Oracle Session.
- ociresult — Gibt einen Spaltenwert für das gefetchte Statement zurück
- ocirollback — Macht ausstehende Transaktionen rückgängig
- ocirowcount — Gibt die Anzahl der betroffenen Zeilen zurück
- ocisavelob — Kommt noch.
- ocisavelobfile — Kommt noch.
- ociserverversion — Return a string containing server version information.
- ocisetprefetch — setzt die Anzahl der Zeilen die vorab gefetcht werden sollen
- ocistatementtype — Gibt den Typ eine Statements zurück
- ociwritelobtofile — Kommt noch.
- ociwritetemporarylob — Alias von OCI-Lob->writeTemporary
Here are the translate of some functions from ORA to OCI:
<?php
function Ora_Logon($usuario, $password)
{
$con = oci_connect($usuario,$password);
return $con;
}
function Ora_Open($conexion) {
$cursor[0]=$conexion;
return $cursor;
}
function Ora_Parse(&$cursor, $consulta) {
$cursor[1]=oci_parse($cursor[0],$consulta);
return $cursor;
}
function Ora_Exec(&$cursor) {
oci_execute($cursor[1]);
$cursor[2]=1;
return $cursor;
}
function Ora_Fetch(&$cursor)
{
if ($cursor[2] == 1) $cursor[2]=0;
return oci_fetch($cursor[1]);
}
function Ora_GetColumn(&$cursor, $indice)
{
if ($cursor[2] == 1) {
Ora_Fetch($cursor);
$cursor[2]=0;
}
$valor = oci_result($cursor[1],$indice+1);
return $valor;
}
function Ora_Close(&$cursor)
{
unset($cursor[1]);
}
function Ora_Logoff($conexion) {
}
?>
