How to use oracle sequence.nextval in PHP  webservice?

Sudhanshum
Sudhanshum used Ask the Experts™
on
We get sequence in asp.net 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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013
Commented:
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.
Most Valuable Expert 2012
Distinguished Expert 2018
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.
Technology Scientist
Commented:
Yes

<?php

// 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');
oci_execute($stid);

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


http://php.net/manual/en/ref.oci8.php
Most Valuable Expert 2012
Distinguished Expert 2018
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 Scientist

Commented:
PHP code provided for connecting to Oracle database and running author's query. Assist points for helpful comments regarding the connection. Split points.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial