1
votes

I had never used PDO for to connect with Informix database before, this error poped up while I was running a basic query:

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

And this is my code:

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

I've tested the same code on Mysql, just change the connection string, and everything works perfect, it seems like the connection string is missing something, and I dont know what it could be.

I followed what is says in this tutorial:

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

1

1 Answers

3
votes

Ummm... try specifing the connection string in just one line.

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# 

Like this:

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#