How to use oracle sequence.nextval in PHP webservice?

We get sequence in using query "select seq.nextval from dual" but i want to use that in PHP webservice  also,is it possible to use oracle sequence in PHP webservice? Can you help me on that?
Who is Participating?
NerdsOfTechConnect With a Mentor Technology ScientistCommented:


// Connects to the XE service (i.e. database) on the "localhost" machine
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

$stid = oci_parse($conn, 'select seq.nextval from dual');

echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    echo "</tr>\n";
echo "</table>\n";


Open in new window
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
I don't know Oracle, but an SQL statement for a given database is going to be the same in any server side language because you are assigning the sql statement to a variable that gets passed to your server side code which accesses the db and sends the sql statement to the db for a response.
slightwv (䄆 Netminder)Connect With a Mentor Commented:
If the PHP web service performs DML at the database, just add seq.nextval to the DML statement.

Unless we see the actual code that is pretty much all I can offer.
slightwv (䄆 Netminder)Connect With a Mentor Commented:
Unless you need the next sequence value in several places outside of the database, I would never make a round trip to the database just to get one.
NerdsOfTechTechnology ScientistCommented:
PHP code provided for connecting to Oracle database and running author's query. Assist points for helpful comments regarding the connection. Split points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.