Re: PDO_INFORMIX error
| From: | Open Source Application Development | Date: | Thu, 01 Dec 2011 08:57:54 +0000 |
| Subject: | Re: PDO_INFORMIX error | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-8937@lists.php.net to get a copy of this message | ||
Hi Bryan,
I tried to reproduce your problem with the PHP script you have given. But
it works fine for me with the both remote server and local server
scenarios.
You may facing this problem because of some odbc environment variables
which i am not able to detect. If you are using some extra ODBC
environment variable then please let us know about that.
Please give us the odbc trace, this may help us in finding the exact
problem in some extend. If you don't know how to take odbc trace then
please go through following link
https://www-304.ibm.com/support/docview.wss?uid=swg21323418
If possible then please try to simulate this test case in native c and
run it with the same environment, If this will also give same exception
then please open a PMR against Informix CSDK.
Thanks,
Rahul
IBM OpenSource Application Development Team
India Software Labs, Bangalore (India)
Bryan Osborne <bryanosborne@yahoo.com>
11/18/2011 03:29 AM
To
pecl-dev@lists.php.net
cc
abhargav@in.ibm.com, Open Source Application Development/Lenexa/IBM@IBMUS
Subject
PDO_INFORMIX error
pdo_informix Team,
Receiving an error when attempting to insert a .gif file into a blob
column.
It would seem the problem is related to the variable being bound in the
$stmt->bindParam(3, $fp_in, PDO::PARAM_LOB);
statement. But, since I'm following convention and using
$file_in = "/tmp/testgraphic.gif";
$fp_in = fopen($file_in, 'rb');
I am quite unsure why I am receiving the error:
Array ( [0] => HY000 [1] => -461 [2] => [Informix][Informix ODBC
Driver][Informix]File open error. (SQLPutData[-461] at
/(path-to-source-code)/PDO_INFORMIX-1.2.6/informix_statement.c:812)) .
I can insert the row if I pass NULL (see code and output below), but not
if I pass the file descriptor (see code and output below). I also receive
the error is I pass in a string (see code below for commented out lines).
I can read and write the file successfully to the file system, so I know
the file is accessable. What kind of "file open" error am I getting here?
I have searched the net and can find no resolution. I have looked at
other posts on the PECL site and can not find this occuring to anyone else
- and I don't like being special! The full php code is below, as well as
the output. I sincerely hope you can help me to understand this!
Bryan
-------------------------------------------------
ENVIRONMENT
------------------------------------------------
Solaris
PHP 5.2.1
PDO_INFORMIX 1.2.6
-------------------------------------------------
PHP CODE
-------------------------------------------------
<?php
try
{
printf("Attempting Connection!\n<br>");
$db = new PDO("informix:host=192.168.1.101; service=1526;database=testdb;
server
=landofoz; protocol=onsoctcp;EnableScrollableCursors=1;", "userid",
"userpwd")
;
printf("Connection Established!\n<br>");
$file_in = "/tmp/testgraphic.gif";
$file_out = "/tmp/testgraphic2.gif";
printf("Opening graphic files $file_in\n<br>");
$fp_in = fopen($file_in, 'rb');
$fp_out = fopen($file_out, 'wb');
$drop_stmt = "drop table testtbl";
$db->query($drop_stmt);
$create_stmt = "create table testtbl ( item_nbr integer, item_desc
char(20), ite
m_img blob)";
$db->query($create_stmt);
$ins_stmt = "insert into testtbl values (1, 'first' , NULL)";
$db->query($ins_stmt);
$ins_stmt = "insert into testtbl values (2, 'second' , NULL)";
$db->query($ins_stmt);
printf("Attempting prepare\n<br>");
$stmt = $db->prepare("insert into testtbl values (?, ?, ?)");
//$stmt = $db->prepare("insert into testtbl values (?, ?, NULL)");
$col_id = 125;
$contenttype = "gifimage";
//$bytestream = "This is a test text.";
printf("Attempting bind\n<br>");
$stmt->bindParam(1, $col_id, PDO::PARAM_INT);
$stmt->bindParam(2, $contenttype, PDO::PARAM_STR);
$stmt->bindParam(3, $fp_in, PDO::PARAM_LOB);
//$stmt->bindParam(3 , $bytestream , PDO::PARAM_LOB , strlen($bytestream)
);
printf("Attempting execute\n<br>");
$stmt->execute();
printf("Insert attempt complete\n<br>");
printf("Error information:\n<br>");
print_r($db->errorInfo());
printf("<br>Attempt to write file\n<br>");
$contents = fread($fp_in, filesize($file_in));
fwrite($fp_out, $contents);
printf("<br>Closing files\n<br>");
fclose($fp_in);
fclose($fp_out);
printf("Attempting query\n<br>");
$stmt2 = $db->prepare("select * from testtbl");
printf("attempting fetch\n<br>");
$res = $stmt2->fetch( PDO::FETCH_BOTH );
$rows = $res[0];
printf("Table contents: $rows.\n<br>");
if ($stmt2->execute(array($_GET['name']))) {
while ($row = $stmt2->fetch()) {
print_r($row);
printf("\n<br>");
}
}
printf("Releasing database\n<br>");
$db = null;
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
-------------------------------------
WEBPAGE OUTPUT
_____________________
Attempting Connection!
Connection Established!
Opening graphic files /tmp/testgraphic.gif
Attempting prepare
Attempting bind
Attempting execute
Insert attempt complete
Error information:
Array ( [0] => HY000 [1] => -461 [2] => [Informix][Informix ODBC
Driver][Informix]File open error. (SQLPutData[-461] at
/path-to-compile-directory)/PDO_INFORMIX-1.2.6/informix_statement.c:812) )
Attempt to write file
Closing files
Attempting query
attempting fetch
Table contents: .
Array ( [ITEM_NBR] => 1 [0] => 1 [ITEM_DESC] => first [1] => first
[ITEM_IMG] => Resource id #5 [2] => Resource id #5 )
Array ( [ITEM_NBR] => 2 [0] => 2 [ITEM_DESC] => second [1] => second
[ITEM_IMG] => Resource id #6 [2] => Resource id #6 )
Releasing database
Thanks,
Bryan
Bryan Osborne
bryanosborne@yahoo.com