troubleshooting Question

PHP 7.4 and Stored Procedure using PDO problem

Avatar of Marthaj Sayers
Marthaj SayersFlag for United States of America asked on
15 Comments1 Solution22 ViewsLast Modified:
I am having two problems with converting some code from PHP 5.6 to PHP 7.4 and using PDO with a
SQL stored procedure (MS SQL Server 2014). It worked just fine in PHP 5.6. No changes have been made to the stored procedure.
I need to insert a new record with some values into a table and return the primary record id of the newly inserted record. There doesn't seem many PDO::parameters available either. I am wondering about the reliability of using PDO for stored procedures as I have read some postings concerning that matter.
It does not work nor does it stop processing. It continues with the application.
If there is an error, I want the program to halt execution.
Two of the incoming values are money - $strIdocMoney and $strFees.
And one is a datetime - $wrkFixedEmailSentDate.
It might be the type of error message in my catch section that I am displaying, but what I am using isn't very helpful at all to track down the problem as it doesn't really tell me anything. Any help with that would be appreciated too.
Below is the coding:
Function InsDocInfoRec($wrkRecvDate, $emailSendDate, $strIdocMoney, $strIDOCNbr)
    $primaryid = '';
    $strRegionId = trim($_SESSION['RegionId']) ;
    $strSecTotal = trim($strIdocMoney);
    $strSecTotal = preg_replace('/[^0-9.-]/', '', $strSecTotal);
    $strSupplier = $_SESSION['GlobalSupplier'];
    $strFees = 0;
$timestamp = strtotime($emailSendDate);
$wrkFixedEmailSentDate = date("Y-m-d", $timestamp);
ECHO '<BR><BR><BR>REGION ID: ' . $strRegionId;
ECHO '<BR>SUPPLIER: ' . $strSupplier;
ECHO '<BR>DATE RECEIVED: ' . $wrkFixedEmailSentDate  . '<BR><BR>';

$connect = new PDO("sqlsrv:Server=$servername;Database=$dbname", $_SESSION['uid'], $_SESSION['pwd']);
    try {

            $insRec = "CALL EXEC ins_new_importIDocInfo(:RegionId,:Supplier,:IDoc,:AmtRcvd,:DateRcvd,:Fees,@RECID)";

            $stmt = $connect->prepare($insRec);
            $stmt->bindParam(':RegionId', $strRegionId, PDO::PARAM_STR); 
            $stmt->bindParam(':Supplier', $strSupplier, PDO::PARAM_STR); 
            $stmt->bindParam(':IDoc', $strIDOCNbr, PDO::PARAM_STR); 
            $stmt->bindParam(':AmtRcvd', $strSecTotal, PDO::PARAM_STR); 
            $stmt->bindParam(':DateRcvd', $wrkFixedEmailSentDate, PDO::PARAM_STR); 
            $stmt->bindParam(':Fees', $strFees,PDO::PARAM_STR);

            $result = $stmt->fetch();
            $primaryid = $result['@RECID'];

            $strLogMsg = $strLogMsg . 'IMPORTIDOCINFO-INSERTED: ' . strval($srtRegionId)
                      . '-' . strval($strSupplier) . '-' . strval($strIDOCNbr)
                      . '-' .  strval($strSecTotal) . '-' .strval($wrkFixedEmailSentDate)
                      . '-' .strval($strPrimaryKeyIdoc) . PHP_EOL;

        } catch (PDOException $e) {
            echo $e->getMessage();
            $errmsg = $e->getMessage();
            echo '<BR>UNABLE TO INSERT RECORD INTO InsDocInfoRec</br>';
            echo '<BR>ERROR MSG: ' . $errmsg;
            echo '<BR>EXITING APPLICATION</br>';
            echo '<BR><BR> ** UNABLE TO INSERT DETAIL LINE INTO InsDocInfoRec **'; 
            $strLogMsg = 'SQL STATEMENT FAILED WITH ERROR: ' . $errmsg . PHP_EOL;
            $nbr = ($nbr + 1);
return $primaryid; 

Open in new window

And this is the only error I receive and then it continues processing.

Open in new window

Any help would be appreciated.. thank you in advance. 
Marthaj Sayers

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 15 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 15 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004