troubleshooting Question

PHP 7.4 and Stored Procedure using PDO problem

Avatar of dogsareit
dogsareitFlag for United States of America asked on
PHP
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)
{
   
// INSERTS ONE PER TEXT FILE
    $primaryid = '';
    $strRegionId = trim($_SESSION['RegionId']) ;
   
    $strSecTotal = trim($strIdocMoney);
    $strSecTotal = preg_replace('/[^0-9.-]/', '', $strSecTotal);
   
    $strSupplier = $_SESSION['GlobalSupplier'];
    $strFees = 0;
   
// NEW DATE FORMAT
$timestamp = strtotime($emailSendDate);
$wrkFixedEmailSentDate = date("Y-m-d", $timestamp);
   
ECHO '<BR><BR><BR>REGION ID: ' . $strRegionId;
ECHO '<BR>SUPPLIER: ' . $strSupplier;
ECHO '<BR>IDOCNBR: ' . $strIDOCNbr;
ECHO '<BR>VENDOR/DETAIL TOTAL: ' . $strSecTotal;
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);

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

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

        } 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;
            RtnWriteLogMsg($strLogMsg);
            $nbr = ($nbr + 1);
            die($e);
      }
      
return $primaryid; 
}                        

And this is the only error I receive and then it continues processing.
C:\wamp\www\Emails\Emails-V7.php:793:null
Any help would be appreciated.. thank you in advance. 
ASKER CERTIFIED SOLUTION
dogsareit

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

Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros