oci_fetch_array 错误,可以通过 php 从 oracle 检索数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5682189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error with oci_fetch_array, can retrieve data from oracle by php
提问by user700792
i can retrieve data from oracle db by php when i try do loop to get data it give me error
当我尝试使用循环获取数据时,我可以通过 php 从 oracle db 检索数据,但它给我错误
undefined index: id in C:\xampp\htdocs\testing\test.php on line 15
未定义索引:第 15 行 C:\xampp\htdocs\testing\test.php 中的 id
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);
?>
回答by Pascal MARTIN
The documentation of oci_fetch_array()
says :
的文档oci_fetch_array()
说:
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.
Oracle 的默认、不区分大小写的列名将在结果数组中具有大写关联索引。区分大小写的列名将具有使用精确列大小写的数组索引。在结果数组上
使用var_dump()
以验证用于每个查询的适当情况。
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 :
而且,如果这仍然不起作用,请按照手册中的说明进行操作:var_dump()
在循环中使用,以查看数据的外观:
while (($row = oci_fetch_array($stid, OCI_BOTH))) {
var_dump($row);
}
回答by ?????
In my case I used NVL
就我而言,我使用了 NVL
The Oracle/PLSQL NVL function lets you substitute a value when a null value is encountered
Oracle/PLSQL NVL 函数允许您在遇到空值时替换一个值
NVL( string1, replace_with )
NVL(字符串1,replace_with)
SELECT NVL(commission, 0) FROM sales;
从销售中选择 NVL(佣金,0);
Output:
输出:
123 223 323
123 223 323
423
423
answer would be like 123 223 323 0 423
答案应该是 123 223 323 0 423