【问题标题】:Informix ODBC Driver... Invalid connection string attribute?Informix ODBC 驱动程序...无效的连接字符串属性?
【发布时间】:2017-12-11 13:54:12
【问题描述】:

我之前从未使用 PDO 连接 Informix 数据库,在运行基本查询时弹出此错误:

SQLSTATE=01S00, SQLDriverConnect: -11005 [Informix][Informix ODBC Driver]Invalid connection string attribute. 

这是我的代码:

<?php

class prueba{
private static $cn = null;

 public static function conectar(){
    if(self::$cn !== null ) {
      return self::$cn;
    }
    try{
       self::$cn= new PDO("informix:host=localhost; service=30000;
    database=mrroot; server=mrserver; protocol=onsoctcp;
    EnableScrollableCursors=1", "mrtony", "");
       return self::$cn;

    } catch (PDOException $ex){
       die($ex->getMessage());
    }
  }


 public static function consulta(){

    $query = "SELECT * FROM fr_envio";

    $cn = prueba::conectar();

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

    $resultado->execute();

        echo '<table>';
        while ($row = $resultado->fetch(PDO::FETCH_ASSOC))
            {
                echo '<tr>';
                echo '<td>'.$row['enviopre'].'</td>';
                echo '<td>'.$row['enviofra'].'</td>';
                echo '<td>'.$row ['enviopec'].'</td>';
                echo '<td>'.$row ['envioval'].'</td>';
                echo '</tr>';
            }

        echo '</table>';

}

}


$prueba = new prueba();

$prueba->consulta();
?>  

我在 Mysql 上测试过同样的代码,只是改变了连接字符串,一切正常,似乎连接字符串丢失了一些东西,我不知道它可能是什么。

我按照本教程中的内容进行操作:

https://www.ibm.com/support/knowledgecenter/en/SSGU8G_12.1.0/com.ibm.virtapp.doc/TD_item2.htm

【问题讨论】:

    标签: php pdo informix


    【解决方案1】:

    嗯...尝试在一行中指定连接字符串。

    root@irk:/usr3/products/php53# cat test.php
    <?php
    
    $db = new PDO("informix:host=irk;service=3046;database=stores7;
    server=irk1210;protocol=onsoctcp;EnableScrollableCursors=1;", "informix", "ximrofni");
    
    print "Connection Established!\n\n";
    
    $stmt = $db->query("select * from systables");
    $res = $stmt->fetch( PDO::FETCH_BOTH );
    $rows = $res[0];
    echo "Table contents: $rows.\n";
    
    
    ?>
    root@irk:/usr3/products/php53# php test.php
    PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE=01S00, SQLDriverConnect: -11005 [Informix][Informix ODBC Driver]Invalid connection string attribute.' in /usr3/products/php5/test.php:4
    Stack trace:
    #0 /usr3/products/php5/test.php(4): PDO->__construct('informix:host=i...', 'informix', 'ximrofni')
    #1 {main}
      thrown in /usr3/products/php5/test.php on line 4
    root@irk:/usr3/products/php53# 
    

    像这样:

    root@irk:/usr3/products/php53# cat test.php
    <?php
    
    $db = new PDO("informix:host=irk;service=3046;database=stores7; server=irk1210;protocol=onsoctcp;EnableScrollableCursors=1;", "informix", "ximrofni");
    
    print "Connection Established!\n\n";
    
    $stmt = $db->query("select * from systables");
    $res = $stmt->fetch( PDO::FETCH_BOTH );
    $rows = $res[0];
    echo "Table contents: $rows.\n";
    
    
    ?>
    root@irk:/usr3/products/php53# php test.php
    Connection Established!
    
    Table contents: systables.
    root@irk:/usr3/products/php53# 
    

    【讨论】:

    • 我是个笨蛋...谢谢哈哈哈,顺便说一句,朋友帮我在ubutu上安装和配置驱动,但他没有告诉我怎么做....你知道有什么教程可以做到这一点吗?除了那些在 stackoverflow 上的,因为我试图用其中的一些来做,但它对我来说并没有成功
    • 除了安装 CSDK 包和设置 env 变量(PATH/INFORMIXDIR)之外,没有太多的东西。看看redbooks.ibm.com/redbooks/pdfs/sg247884.pdf它有很多关于如何使用不同的Informix API(包括ODBC)的示例和一些基本的故障排除。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    • 2013-11-11
    相关资源
    最近更新 更多