8.88 Fonctions Oracle
8 Référence des fonctions
Manuel PHP
. Introduction . Pré-requis . Configuration à l'exécution . Constantes pré-définies ->Exemples . Gestion de la connexion . Types de données supportées par le driver . oci_bind_by_name . oci_cancel . oci_close . OCI-Collection->append . OCI-Collection->assign . OCI-Collection->assignElem . OCI-Collection->free . OCI-Collection->getElem . OCI-Collection->max . OCI-Collection->size . OCI-Collection->trim . oci_commit . oci_connect . oci_define_by_name . oci_error . oci_execute . oci_fetch_all . oci_fetch_array . oci_fetch_assoc . oci_fetch_object . oci_fetch_row . oci_fetch . oci_field_is_null . oci_field_name . oci_field_precision . oci_field_scale . oci_field_size . oci_field_type_raw . oci_field_type . oci_free_statement . oci_internal_debug . OCI-Lob->append . OCI-Lob->close . oci_lob_copy . OCI-Lob->eof . OCI-Lob->erase . OCI-Lob->export . OCI-Lob->flush . OCI-Lob->free . OCI-Lob->getBuffering . OCI-Lob->import . oci_lob_is_equal . OCI-Lob->load . OCI-Lob->read . OCI-Lob->rewind . OCI-Lob->save . OCI-Lob->saveFile . OCI-Lob->seek . OCI-Lob->setBuffering . OCI-Lob->size . OCI-Lob->tell . OCI-Lob->truncate . OCI-Lob->write . OCI-Lob->writeTemporary . OCI-Lob->writeToFile . oci_new_collection . oci_new_connect . oci_new_cursor . oci_new_descriptor . oci_num_fields . oci_num_rows . oci_parse . oci_password_change . oci_pconnect . oci_result . oci_rollback . oci_server_version . oci_set_prefetch . oci_statement_type . ocibindbyname . ocicancel . ocicloselob . ocicollappend . ocicollassign . ocicollassignelem . ocicollgetelem . ocicollmax . ocicollsize . ocicolltrim . ocicolumnisnull . ocicolumnname . ocicolumnprecision . ocicolumnscale . ocicolumnsize . ocicolumntype . ocicolumntyperaw . ocicommit . ocidefinebyname . ocierror . ociexecute . ocifetch . ocifetchinto . ocifetchistatement . ocifreecollection . ocifreecursor . ocifreedesc . ocifreestatement . ociinternaldebug . ociloadlob . ocilogoff . ocilogon . ocinewcollection . ocinewcursor . ocinewscriptor . ocinlogon . ocinumcols . ociparse . ociplogon . ociresult . ocirollback . ocirowcount . ocisavelob . ocisavelobfile . ociserverversion . ocisetprefetch . ocistatementtype . ociwritelobtofile . ociwritetemporarylob
|
8.88.5 Exemples
| Requête basique |
<?php
$conn = oci_connect('hr', 'hr', 'orcl'); if (!$conn) { $e = oci_error(); print htmlentities($e['message']); exit; }
$query = 'SELECT * FROM DEPARTMENTS';
$stid = oci_parse($conn, $query); if (!$stid) { $e = oci_error($conn); print htmlentities($e['message']); exit; }
$r = oci_execute($stid, OCI_DEFAULT); if (!$r) { $e = oci_error($stid); echo htmlentities($e['message']); exit; }
print '<table border="1">'; while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) { print '<tr>'; foreach ($row as $item) { print '<td>'.($item?htmlentities($item):' ').'</td>'; } print '</tr>'; } print '</table>';
oci_close($conn); ?>
|
| Requête Insert avec des variables liées |
<?php
// Avant d'exécuter, création de la table // CREATE TABLE MYTABLE (mid NUMBER, myd VARCHAR2(20));
$conn = oci_connect('scott', 'tiger', 'orcl');
$query = 'INSERT INTO MYTABLE VALUES(:myid, :mydata)';
$stid = oci_parse($conn, $query);
$id = 60; $data = 'Some data';
oci_bind_by_name($stid, ':myid', $id); oci_bind_by_name($stid, ':mydata', $data);
$r = oci_execute($stid);
if ($r) print "Une ligne a été insérée";
oci_close($conn);
?>
|
| Insertion de donnée dans une colonne CLOB |
<?php
// Avant l'exécution, création de la table // CREATE TABLE MYTABLE (mykey NUMBER, myclob CLOB);
$conn = oci_connect('scott', 'tiger', 'orcl');
$mykey = 12343; // clé arbitraire pour cette exemple;
$sql = "INSERT INTO mytable (mykey, myclob) VALUES (:mykey, EMPTY_CLOB()) RETURNING myclob INTO :myclob";
$stid = oci_parse($conn, $sql); $clob = oci_new_descriptor($conn, OCI_D_LOB); oci_bind_by_name($stid, ":mykey", $mykey, 5); oci_bind_by_name($stid, ":myclob", $clob, -1, OCI_B_CLOB); oci_execute($stid, OCI_DEFAULT); $clob->save("A very long string");
oci_commit($conn);
// Récupération des données CLOB
$query = 'SELECT myclob FROM mytable WHERE mykey = :mykey';
$stid = oci_parse ($conn, $query); oci_bind_by_name($stid, ":mykey", $mykey, 5); oci_execute($stid, OCI_DEFAULT);
print '<table border="1">'; while ($row = oci_fetch_array($stid, OCI_ASSOC)) { $result = $row['MYCLOB']->load(); print '<tr><td>'.$result.'</td></tr>'; } print '</table>';
?>
|
Vous pouvez facilement accéder aux procédures stockées, de la même
façon que vous le feriez par ligne de commande :
| Utilisation de procédures stockées |
<?php // par webmaster@remoterealty.com $sth = oci_parse($dbh, "begin sp_newaddress( :address_id, '$firstname', '$lastname', '$company', '$address1', '$address2', '$city', '$state', '$postalcode', '$country', :error_code );end;" );
// Cela appelle la procédure stockée sp_newaddress, avec la variable :address_id // pour les entrées/sorties et :error_code comme variable de sortie. // Ensuite, vous faites les liaisons suivantes :
oci_bind_by_name($sth, ":address_id", $addr_id, 10); oci_bind_by_name($sth, ":error_code", $errorcode, 10); oci_execute($sth);
?>
|
|