使用 odbc/db2 查询的 php 数组中的非法字符串偏移量
illegal string offset in php array with odbc/db2 query
我是运行这个函数,它正在为每一列选择数据和我"m having it thrown into another function for inserting but upon errors and doing a var_dump of my results (which successfully dumped an array) I'm getting "非法字符串偏移量”
尽管我正在转换这些值,但我的数组基本上是将每个值打印为字符串 (1) "number" 或字符串(10) "value" 所以我知道我没有列名在这里作为索引。
我做错了什么?
编辑:错误消息 PHP Warning: Illegal string offset 'QT' in line 38
public function ref()
{
$sql = "select cast(co as DECIMAL) as co,
cast(sl as DECIMAL)as sl,
cast(pr as character(10)) as pr,
cast(qt as decimal) as qt
FROM tableOne";
$results = odbc_exec($this->DB2Conn, $sql);
$log='';
if ($results) {
while($row = odbc_fetch_array($results)) {
foreach($row as $r){
$res = $this->add($r['sl'], $r['pr'], $r['qt'], $r['co']);
}
}
}
return $log;
}
不需要你的内部foreach
if ($results) {
while($r = odbc_fetch_array($results)) {
$res = $this->add($r['sl'], $r['pr'], $r['qt'], $r['co']);
}
}
此处将结果作为 array():
加载到 $row
while($row = odbc_fetch_array($results)) {
在这里你遍历 $row ...
foreach($row as $r){
...所以这里的 $r 是标量而不是数组。
$res = $this->add($r['sl'], $r['pr'], $r['qt'], $r['co']);
可能的解决方案(细节太少,不准确):
while($row = odbc_fetch_array($results)) {
$res = $this->add($row['sl'], $row['pr'], $row['qt'], $row['co']);
}
我是运行这个函数,它正在为每一列选择数据和我"m having it thrown into another function for inserting but upon errors and doing a var_dump of my results (which successfully dumped an array) I'm getting "非法字符串偏移量”
尽管我正在转换这些值,但我的数组基本上是将每个值打印为字符串 (1) "number" 或字符串(10) "value" 所以我知道我没有列名在这里作为索引。
我做错了什么?
编辑:错误消息 PHP Warning: Illegal string offset 'QT' in line 38
public function ref()
{
$sql = "select cast(co as DECIMAL) as co,
cast(sl as DECIMAL)as sl,
cast(pr as character(10)) as pr,
cast(qt as decimal) as qt
FROM tableOne";
$results = odbc_exec($this->DB2Conn, $sql);
$log='';
if ($results) {
while($row = odbc_fetch_array($results)) {
foreach($row as $r){
$res = $this->add($r['sl'], $r['pr'], $r['qt'], $r['co']);
}
}
}
return $log;
}
不需要你的内部foreach
if ($results) {
while($r = odbc_fetch_array($results)) {
$res = $this->add($r['sl'], $r['pr'], $r['qt'], $r['co']);
}
}
此处将结果作为 array():
加载到 $rowwhile($row = odbc_fetch_array($results)) {
在这里你遍历 $row ...
foreach($row as $r){
...所以这里的 $r 是标量而不是数组。
$res = $this->add($r['sl'], $r['pr'], $r['qt'], $r['co']);
可能的解决方案(细节太少,不准确):
while($row = odbc_fetch_array($results)) {
$res = $this->add($row['sl'], $row['pr'], $row['qt'], $row['co']);
}