P. 1
phpyoracle

phpyoracle

|Views: 623|Likes:
Published by Dunkel Kruspe

More info:

Categories:Types, Research
Published by: Dunkel Kruspe on Apr 05, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/03/2011

pdf

text

original

To see the transactional behavior of the three connection functions, use SQL*Plus to create a table with a
single date column:

SQL> create table mytable (col1 date);

Rerun transactions.php a few times, changing oci_connect() to oci_new_connect() and
oci_pconnect():

Script 15: transactions.php

function do_query($c, $query)
{

$s = oci_parse($c, $query);
oci_execute($s, OCI_DEFAULT);
oci_fetch_all($s, $res);
echo "

";
var_dump($res); // PHP debugging function for displaying output
echo "
";

}

$c1 = oci_connect("hr", "hrpwd", "localhost/XE"); // first connection
$s = oci_parse($c1, "insert into mytable values ('" . date('j:M:y') . "')");
oci_execute($s, OCI_DEFAULT); // does not commit
do_query($c1, "select * from mytable");

$c2 = oci_connect("hr", "hrpwd", "localhost/XE"); // second connection
do_query($c2, "select * from mytable");

?>

The script inserts (but does not commit) using one connection and queries back the results with the original
and a second connection.

Using an oci_connect() connection lets you query the newly inserted (but uncommitted) data both
times because $c1 and $c2 refer to the same Oracle connection. Using oci_pconnect() is the same as
oci_connect(). The output is:
array(1) {
["COL1"]=>
array(1) {
[0]=>
string(9) "16-JUN-07"

}

}
array(1) {
["COL1"]=>
array(1) {
[0]=>
string(9) "16-JUN-07"

}

137

Executing SQL Statements With OCI8

}

Using oci_new_connect() for $c2 gives a new connection which cannot see the uncommitted data. The
output shows the second query does not fetch any rows:

array(1) {
["COL1"]=>
array(1) {
[0]=>
string(9) "16-JUN-07"

}

}
array(1) {
["COL1"]=>
array(0) {
}

}

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->