Sommaire
Oracle 8
ociDefineByName
ociBindByName
ociLogon
ociPLogon
ociNLogon
ociLogOff
ociexecute
ociCommit
ociRollback
ociNewDescriptor
ociRowCount
ociNumCols
ociResult
ociFetch
ociFetchInto
ociFetchStatement
ociColumnIsNULL
ociColumnName
ociColumnSize
ociColumnType
ociServerVersion
ociStatementType
ociNewCursor
ociFreeStatement
ociFreeCursor
ociFreeDesc
ociparse
ociError
ociinternaldebug
OCICancel
ocisetprefetch
OCIWriteLobToFile
OCISaveLobFile
OCISaveLob
OCILoadLob
OCIColumnScale
OCIColumnPrecision
OCIColumnTypeRaw
OCINewCollection
OCIFreeCollection
OCICollAssign
OCICollAssignElem
OCICollGetElem
OCICollMax
OCICollSize
OCICollTrim
|
6.68.3 ociLogon[ Exemples avec ociLogon ] Description
resource ocilogon(string username ,string password ,[string db ])
ocilogon retourne un identifiant de connexion,
nécessaire à la plupart des fonctions oci. Si l'option
ORACLE_SID n'est pas précisée, PHP utilisera la variable
d'environnement ORACLE_SID pour déterminer le serveur de connexion.
Les connexions sont partagées, à l'intérieur
d'une même page avec ocilogon. Cela signifie
que COMMIT et ROLLBACK s'appliquent à toutes les transactions
commencées à l'intérieur d'une même page,
même si vous avez créé de multiples connexions.
Cet exemple montre comment les connexions sont partagées :
ociLogon |
<?php print "<HTML><PRE>"; $db = ""; $c1 = ocilogon("scott","tiger",$db); $c2 = ocilogon("scott","tiger",$db); function create_table($conn) { $stmt = ociparse($conn,"create table scott.hallo (test varchar2(64))"); ociexecute($stmt); echo $conn." created table\n\n"; } function drop_table($conn) { $stmt = ociparse($conn,"drop table scott.hallo"); ociexecute($stmt); echo $conn." dropped table\n\n"; } function insert_data($conn) { $stmt = ociparse($conn,"insert into scott.hallo values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY HH24:MI:SS'))"); ociexecute($stmt,oci_DEFAULT); echo $conn." inserted hallo\n\n"; } function delete_data($conn) { $stmt = ociparse($conn,"delete from scott.hallo"); ociexecute($stmt,oci_DEFAULT); echo $conn." deleted hallo\n\n"; } function commit($conn) { ocicommit($conn); echo $conn." commited\n\n"; } function rollback($conn) { ocirollback($conn); echo $conn." rollback\n\n"; } function select_data($conn) { $stmt = ociparse($conn,"select * from scott.hallo"); ociexecute($stmt,oci_DEFAULT); echo $conn."----selecting\n\n"; while (ocifetch($stmt)) echo $conn." <".ociresult($stmt,"TEST").">\n\n"; echo $conn."----done\n\n"; } create_table($c1); insert_data($c1); // Insertion d'une ligne avec c1 insert_data($c2); // Insertion d'une ligne avec c2 select_data($c1); // Les résultats des deux insertions sont retournés select_data($c2); rollback($c1); // Annulation avec c1 select_data($c1); // Les résultats des deux insertions sont annulés select_data($c2); insert_data($c2); // Insertion d'une ligne avec c2 commit($c2); // Validation avec using c2 select_data($c1); // Le résultat de c2 est retourné delete_data($c1); // Effacement de toutes les lignes avec c1 select_data($c1); // Aucune ligne n'est retournée select_data($c2); // Aucune ligne n'est retournée commit($c1); // Validation avec c1 select_data($c1); // Aucune ligne n'est retournée select_data($c2); // Aucune ligne n'est retournée drop_table($c1); print "</PRE></HTML>"; ?>
|
Voir aussi
ociplogon et
ocinlogon.
|