Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:10:17+00:00 2026-05-26T18:10:17+00:00

From PHP, I am calling a SQL stored procedure. The stored procedure checks the

  • 0

From PHP, I am calling a SQL stored procedure. The stored procedure checks the database, and either inserts the data if it’s new, or modifies data that already exists.

I’m getting an error that one of my parameters is of an incorrect data type. I can’t really control this because of where the data is coming from. I am calling the stored procedure hundreds, or thousands of times looping through an array of data, and I only get this error for a couple of records out of the batch.

What is the proper way to handle this error in the stored procedure? If any of the parameters have the incorrect data type, I just want to skip that record and move on to the next record. Each call comes from a foreach loop.

The database is reporting the error and PHP is displaying it. I do not have experience with error handling.

Example PHP Code:

foreach($item_array as $item) {
    $id = $item['id'];
    $color = $item['color'];

    $con = connect()
    $query = 'EXECUTE PROCEDURE sp_update_db(:id, :color);'
    $params = array(':id' => $id, ':color' => $color);
    $stmt = prepare($con, $query);

    $result = execute($stmt, $params);

    close($con);
}

Running the code I get “Warning: SQL error: [stored procedure a paramater was of the incorrect datatype]”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:10:17+00:00Added an answer on May 26, 2026 at 6:10 pm

    Looks to me that your proc is not even executed as a result of the wrong parameter being passed; you can only handle this on your php code by catching the exception.

    If the proc is in fact being called, but simply failling inside the procedure due to some sort of data type mismatch, you can use

    BEGIN TRY
        -- your proc statements here
    END TRY
    BEGIN CATCH
    END CATCH
    

    Documentation here.

    UPDATE

    Since you said that you are calling the proc once per each record that you need to process, you need to catch the error on the PHP side. You can use try/catch blocks on PHP. See here.

    Basically, you’d need to have the try/catch block inside your foreach loop enclosing only the part that calls the stored procedure; however, I would just have an if statement before the stored procedure call that makes sure all the parameters that will be passed to the proc are of the expected type and lenght. For example, if stored procedure expectes parameter @a of type int, I would prevent the proc from being called at all if the parameter that is about to be passed is not a number or an empty string.

    UPDATE 2

    Based on sample php (Warning: I am not a PHP coder), seems like this will work:

    try{
        $result = execute($stmt, $params);
    }
    catch (Exception $e) {
    }
    

    But again, if you know the data types expected by the proc, why not have an if instead of the try/catch?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm calling a php function from my $.ajax call to add a new item
In MySQL is a prepared statement inside a stored procedure safe from SQL injection?
So I am calling an API written in VB.NET from PHP and passing it
I am calling a python script from PHP. The python program has to return
from my understanding, require pastes code into the calling php file. what if you
So I am trying to execute some script from my php code. That lives
I'm calling the php code from ajax like this: ajaxRequest.open(GET, func.php + queryString, true);
I am calling a simple JOIN SQL on a mySQL database. The exact query
I have a function that is calling a php page on a remote server
I am having problems calling a URL from PHP code. I need to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.