Skip to content

Instantly share code, notes, and snippets.

@NattyNarwhal
Last active Jul 12, 2021
Embed
What would you like to do?
Reproduction for SQL_NO_TOTAL bug with PDO_ODBC
<?php
$dbconn = new PDO("odbc:Driver=IBM i Access ODBC Driver;System=system", $user, $password);
$sql = "call DBTEST.getCusInfo(?, ?, ?, ?)";
$dbconn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$stmt = $dbconn->prepare($sql);
if (($err = $stmt->errorInfo()) && $err[0]) print_r($err);
$Customer = new stdClass();
$Customer->ID = 1;
$Customer->Data1 = "";
$Customer->Data2 = "";
$Customer->Data3 = 1;
$stmt->bindParam(1, $Customer->ID, PDO::PARAM_INT);
if (($err = $stmt->errorInfo()) && $err[0]) print_r($err);
// Crash occurs when this is 20, instead of 21 (or omitting length)
$stmt->bindParam(2, $Customer->Data1, PDO::PARAM_INPUT_OUTPUT | PDO::PARAM_STR, 20);
if (($err = $stmt->errorInfo()) && $err[0]) print_r($err);
// Crash occurs when this is 25, instead of 26 (or omitting length)
$stmt->bindParam(3, $Customer->Data2, PDO::PARAM_INPUT_OUTPUT | PDO::PARAM_STR, 25);
if (($err = $stmt->errorInfo()) && $err[0]) print_r($err);
$stmt->bindParam(4, $Customer->Data3, PDO::PARAM_INPUT_OUTPUT | PDO::PARAM_INT, 10);
if (($err = $stmt->errorInfo()) && $err[0]) print_r($err);
$stmt->execute();
if (($err = $stmt->errorInfo()) && $err[0] && ($err[0] != '00000')) print_r($err);
var_dump($Customer);
**FREE
Ctl-Opt DftActGrp(*No) ActGrp(*New);
Dcl-Pi GetCusInfo;
pCusID Int(10);
pCusName Char(20);
pCusEmail Char(25);
pCusAge Int(10);
END-PI;
Select;
When (pCusID = 1);
pCusName = '5char';
pCusEmail = 'xxxxxxxxxxxxxxxxxxx';
pCusAge = 19;
When (pCusID = 2);
pcusName = ' 8chars';
pCusEmail = 'xxxxxxxxxxxxxxxxx';
pCusAge = 19;
When (pCusID = 3);
pcusName = ' 8chars';
pCusEmail = 'xxxxxxxxxxxxxxxx';
pCusAge = 41;
When (pCusID = 4);
pcusName = '5char';
pCusEmail = 'xxxxxxxxxxxxxxxxx';
pCusAge = 48;
ENDSL;
*InLR = *On;
Return;
-- SQL is Db2 for i
CREATE PROCEDURE DBTEST/GETCUSINFO (
IN CUSID INTEGER ,
OUT CUSNAME CHAR(20) ,
OUT CUSEMAIL CHAR(25) ,
OUT PCUSAGE INTEGER )
LANGUAGE RPGLE
SPECIFIC DBTEST/GETCUSINFO
NOT DETERMINISTIC
MODIFIES SQL DATA
CALLED ON NULL INPUT
EXTERNAL NAME 'DBTEST/GETCUSINFO'
PARAMETER STYLE GENERAL ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment