Reputation: 253
I'm trying to output the data from a specific table within my Oracle SQL Developer database using a PHP form. I had some experience with this concept in the past using MySQL but I'm struggling to understand the differences between integrating it using Oracle specific syntax now.
My code is ideally laid out but when I run the code I get an error regarding the OCI_FETCH_ARRAY parameters, which I'm unsure on how to solve.
My Code
<?php
include("../connection.php");
error_reporting(E_ALL);
$sql = 'SELECT * FROM ALGORITHM';
$stid = oci_parse($conn, $sql);
echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Name</th> <th>Description<th> </tr>";
while($row= oci_fetch_array($stid, $sql))
{
echo "<tr>";
echo "<td>" . $row ['Algorithm_ID'] . "</td>";
echo "<td>" . $row ['Algorithm_Name'] . "</td>";
echo "<td>" . $row ['Algorithm_Role'] . "</td>";
echo "</tr>";
}
echo "</table>";
oci_free_statement($stid);
oci_close($conn);
?>
The Error I keep getting
Warning: oci_fetch_array() expects parameter 2 to be integer, string given in /studenthome.hallam.shu.ac.uk/STUDENTHOME8/1/b5040831/public_html/ADM/bin/php/entities/database.php on line 12
I get that it's asking for an integer, but why? In the MySQL concept you simply outline the connection string it was never an issue.
Can anyone help ?
Upvotes: 1
Views: 330
Reputation: 57131
Calling oci_fetch_array()
( from http://php.net/manual/en/function.oci-fetch-array.php) should be called like
while($row= oci_fetch_array($stid))
The second parameter is the mode - i.e. OCI_ASSOC
.
Update: when using oci_parse()
, this doesn't actually execute the parsed statement, you need to do...
oci_execute($stid);
So your code would be something like...
$sql = 'SELECT * FROM ALGORITHM';
$stid = oci_parse($conn, $sql);
oci_execute($stid);
echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Name</th> <th>Description<th> </tr>";
while($row= oci_fetch_array($stid, OCI_ASSOC))
(Look at http://php.net/manual/en/function.oci-parse.php for code examples)
Upvotes: 3