gpt4 book ai didi

javascript - 从 Informix 数据库返回的数据作为 php 中的未定义索引?

转载 作者:行者123 更新时间:2023-11-30 20:55:01 26 4
gpt4 key购买 nike

我得到了这个错误,每行次数:

Notice: Undefined index: enviopre in /opt/lampp/htdocs/pruebax/pruebaxone.php on line 34

Notice: Undefined index: enviofra in /opt/lampp/htdocs/pruebax/pruebaxone.php on line 35

Notice: Undefined index: enviofec in /opt/lampp/htdocs/pruebax/pruebaxone.php on line 36

Notice: Undefined index: envioval in /opt/lampp/htdocs/pruebax/pruebaxone.php on line 37
.
.
.

这意味着返回表中的所有值,但它不能存储在数组中。我尝试更改每个 $row 接收参数的方式,而不是使用数组编号中的位置的字段名称,例如:$row[1] $row[2] $row[3] ...还是不行...

这是我的代码:

<?php


class pruebax{
private static $cn = null;

public static function conectar(){
if (self::$cn !==null){
return self::$cnn;
}

try{
$cn = new PDO("informix:host=localhost; service=30000;database=mrroot; server=mrserver;protocol=onsoctcp;EnableScrollableCursors=1", "mrtony", "");

return $cn;

}catch (PDOException $ex){

die($ex->getMessege());

}
}
}

public static function consulta(){

$query = "SELECT * FROM fr_envio";

$cn = pruebaxone::conectar();

$resultado = $cnx->prepare($query);

$resultado->execute();


$rows = $query->fetch(PDO::FETCH_ASSOC);
echo '<table>';
foreach ($rows as $row){

echo '<tr>';
echo '<td>'.$row['enviopre'].'</td>';
echo '<td>'.$row['enviofra'].'</td>';
echo '<td>'.$row['enviofec'].'</td>';
echo '<td>'.$row['envioval'].'</td>';
echo '</tr>';

}
echo '</table>';
}

$prueba = new pruebaxone();
$prueba->consulta();

?>

抱歉,如果我犯了一个明显的错误,我正在学习...

最佳答案

尝试用大写字母指定列:

root@irk:/usr3/products/php53# cat i.php
<?php

$db = new PDO("informix:host=irk;service=3046;database=stores7;server=irk1210;protocol=onsoctcp;EnableScrollableCursors=1;client_LOCALE=en_Us.utf8;db_locale=en_us.819;OPTIMIZEAUTOCOMMIT=1;", "informix", "ximrofni");

print "Connection Established!\n\n";

$resultado = $db->query("select first 5 * from systables");
$resultado->execute();
echo '<table>';
while ($row = $resultado->fetch(PDO::FETCH_ASSOC))
{
echo '<tr>';
echo '<td>'.$row['TABID'].'</td>';
echo '<td>'.$row['TABNAME'].'</td>';
echo '<td>'.$row ['OWNER'].'</td>';
echo '</tr>';
}
echo '</table>';
?>
root@irk:/usr3/products/php53# php i.php
Connection Established!

<table><tr><td>1</td><td>systables</td><td>informix </td></tr>
<tr><td>2</td><td>syscolumns</td><td>informix </td></tr>
<tr><td>3</td><td>sysindices</td><td>informix </td></tr>
<tr><td>4</td><td>systabauth</td><td>informix </td></tr>
<tr><td>5</td><td>syscolauth</td><td>informix </td></tr></table>
root@irk:/usr3/products/php53#

关于javascript - 从 Informix 数据库返回的数据作为 php 中的未定义索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47760503/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com