Reputation: 2249
i can retrieve data from oracle db by php when i try do loop to get data it give me error
undefined index: id in C:\xampp\htdocs\testing\test.php on line 15
here is my code
<?php
$username = "kemo";
$password = "kemoacer77";
$server = "localhost/XE";
$conn = oci_connect($username, $password, $server);
if(!$conn){
die("connect error".oci_error());
}
$stid = oci_parse($conn, 'SELECT id, username FROM users');
oci_execute($stid);
while (($row = oci_fetch_array($stid, OCI_BOTH))) {
// Use the uppercase column names for the associative array indices
echo $row['id'] ;
echo $row['username'];
}
oci_free_statement($stid);
oci_close($conn);
?>
Upvotes: 0
Views: 6201
Reputation: 51
In my case I used NVL
The Oracle/PLSQL NVL function lets you substitute a value when a null value is encountered
NVL( string1, replace_with )
SELECT NVL(commission, 0) FROM sales;
Output:
123 223 323
423
answer would be like 123 223 323 0 423
Upvotes: 0
Reputation: 400982
The documentation of oci_fetch_array()
says :
Oracle's default, non-case sensitive column names will have uppercase associative indices in the result array. Case-sensitive column names will have array indices using the exact column case.
Usevar_dump()
on the result array to verify the appropriate case to use for each query.
And the comment in your code also says :
// Use the uppercase column names for the associative array indices
So, why are you using lowercase column names ?
This is your code :
echo $row['id'] ;
echo $row['username'];
According to the comment in your code, and the note in the manual, should you not use uppercase, like this :
echo $row['ID'] ;
echo $row['USERNAME'];
And, if this still doesn't work, just do as said in the manual : use var_dump()
in your loop, to see how your data looks like :
while (($row = oci_fetch_array($stid, OCI_BOTH))) {
var_dump($row);
}
Upvotes: 1