从Informix数据库返回的数据作为php上的unifined索引?

时间:2017-12-11 20:00:14

标签: javascript php informix

我收到了这个错误,每行一次:

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();

?>

对不起,如果我犯了一个明显的错误,我正在学习......

1 个答案:

答案 0 :(得分:1)

尝试以大写形式指定列:

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#