How to pass multiple parameters to stored procedure using pdo in php

Anil kumar

I've a procedure which takes multiple params as input and gives output to one variable

here i'm pasting my code below.

Updated

$sqlStr = 'call sp_testproc(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);';
$c = new PDO("sqlsrv:Server=localhost;Database=testdb", "UserName", "Password");
$stmt = $c->prepare($sqlStr);

$bindValues = array(
    'fields' => array(
       array('type' => 'input', 'name' => ':From', 'value' => '[email protected]', 'data_type' => PDO::PARAM_STR),
        array('type' => 'input', 'name' => ':To', 'value' => '[email protected]', 'data_type' => PDO::PARAM_STR),
        array('type' => 'input', 'name' => ':Cc', 'value' => '', 'data_type' => PDO::PARAM_STR),
        array('type' => 'input', 'name' => ':Bcc', 'value' => '', 'data_type' => PDO::PARAM_STR),
        array('type' => 'input', 'name' => ':Subject', 'value' => 'some value given', 'data_type' => PDO::PARAM_STR),
        array('type' => 'input', 'name' => ':someId', 'value' => 10334, 'data_type' => PDO::PARAM_INT),
        array('type' => 'input', 'name' => ':someId1', 'value' => 307560, 'data_type' => PDO::PARAM_INT),
        array('type' => 'input', 'name' => ':ReadOrUnread', 'value' => 1, 'data_type' => PDO::PARAM_INT),
        array('type' => 'input', 'name' => ':HasAttachments', 'value' => 1, 'data_type' => PDO::PARAM_INT),
        array('type' => 'input', 'name' => ':someId2', 'value' => 9, 'data_type' => PDO::PARAM_INT),
        array('type' => 'input', 'name' => ':someId3', 'value' => 89, 'data_type' => PDO::PARAM_INT),
        array('type' => 'input', 'name' => ':link', 'value' => 'http:google.com', 'data_type' => PDO::PARAM_STR),
        array('type' => 'input', 'name' => ':someId4', 'value' => 3998, 'data_type' => PDO::PARAM_STR),
        array('type' => 'input', 'name' => ':MailDate', 'value' => '2014-02-01', 'data_type' => PDO::PARAM_STR),
        array('type' => 'output', 'value' => '$Id', 'data_type' => PDO::PARAM_INPUT_OUTPUT),
    )
);

$proc_pass_val = null;
if (isset($bindValues['fields']) && is_array($bindValues['fields'])) {
    $arg_cnt = 1;
    for ($i = 0; $i < count($bindValues['fields']); $i++) {
        $bindValue = $bindValues['fields'][$i]["value"];
        $param_type = $bindValues['fields'][$i]["type"];
        $data_type = $bindValues['fields'][$i]["data_type"];

        if ($param_type == 'input') {
            $stmt->bindValue($arg_cnt++, $bindValue, $data_type);
        } elseif ($param_type == 'output') {
            $stmt->bindParam($arg_cnt++, $proc_pass_val, $data_type);
        }
    }
}


$stmt->execute();

print "procedure returned $proc_pass_val\n";

Note: I'm using MSSQL server

I want the Procedure output in $Id variable, please suggest me where i went wrong

Thanks in Advance

Anil kumar

I just passed the parameter length to bindParam like this

$stmt->bindParam($arg_cnt++, $proc_pass_val, $data_type, [Length of the data type])

and it worked for me

the code is more readable in this solution

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to pass multiple values using stored procedure?

From Dev

how to pass parameters to a stored procedure using @NamedNativeQuery in spring hibernate

From Dev

how to pass parameters to a stored procedure using @NamedNativeQuery in spring hibernate

From Dev

How to execute a stored procedure in php using sqlsrv and "?" style parameters

From Dev

pymysql how to pass parameters for a stored procedure

From Dev

PDO OCI PHP pass array parameter to stored procedure

From Dev

Is there a more cleaner or elegant way to pass multiple parameters to SQL stored procedure using Entity Framework?

From Dev

How to know the stored procedure parameters in PHP?

From Dev

Pass parameters in a stored procedure in Spring

From Dev

Pass multiple parameters in PDO

From Dev

Mybatis + stored procedure - How to Pass a long value to a procedure using mybatis

From Dev

Stored procedure that accepts multiple parameters

From Dev

How to return multiple rows using Stored Procedure

From Dev

How to return multiple rows using Stored Procedure

From Dev

Pass multiple values to stored procedure

From Dev

How to Use Multiple Parameters in a MySQL *Prepared* Stored Procedure

From Dev

How to Use Multiple Parameters in a MySQL *Prepared* Stored Procedure

From Dev

MySQL stored procedure on a read replica with PHP PDO

From Dev

Pass parameters to Stored Procedure with single quotes

From Dev

Can you pass a series of parameters to a stored procedure

From Dev

How to run a stored procedure without changing the as of date parameters using autosys

From Dev

Calling stored procedure from PHP using PDO to MSSQL Server using INPUT Paramters

From Dev

MySQL Stored Procedure not working with multiple parameters

From Dev

SQL - Creating a stored procedure with multiple optional parameters

From Dev

ArgumentException on Adding multiple Parameters in Stored Procedure

From Dev

Sending multiple parameters to stored procedure with jQuery Ajax

From Dev

How to pass parameters to a procedure in assembly?

From Dev

How to return multiple resultset from a stored procedure using cte?

From Dev

PDO stored procedure call

Related Related

  1. 1

    how to pass multiple values using stored procedure?

  2. 2

    how to pass parameters to a stored procedure using @NamedNativeQuery in spring hibernate

  3. 3

    how to pass parameters to a stored procedure using @NamedNativeQuery in spring hibernate

  4. 4

    How to execute a stored procedure in php using sqlsrv and "?" style parameters

  5. 5

    pymysql how to pass parameters for a stored procedure

  6. 6

    PDO OCI PHP pass array parameter to stored procedure

  7. 7

    Is there a more cleaner or elegant way to pass multiple parameters to SQL stored procedure using Entity Framework?

  8. 8

    How to know the stored procedure parameters in PHP?

  9. 9

    Pass parameters in a stored procedure in Spring

  10. 10

    Pass multiple parameters in PDO

  11. 11

    Mybatis + stored procedure - How to Pass a long value to a procedure using mybatis

  12. 12

    Stored procedure that accepts multiple parameters

  13. 13

    How to return multiple rows using Stored Procedure

  14. 14

    How to return multiple rows using Stored Procedure

  15. 15

    Pass multiple values to stored procedure

  16. 16

    How to Use Multiple Parameters in a MySQL *Prepared* Stored Procedure

  17. 17

    How to Use Multiple Parameters in a MySQL *Prepared* Stored Procedure

  18. 18

    MySQL stored procedure on a read replica with PHP PDO

  19. 19

    Pass parameters to Stored Procedure with single quotes

  20. 20

    Can you pass a series of parameters to a stored procedure

  21. 21

    How to run a stored procedure without changing the as of date parameters using autosys

  22. 22

    Calling stored procedure from PHP using PDO to MSSQL Server using INPUT Paramters

  23. 23

    MySQL Stored Procedure not working with multiple parameters

  24. 24

    SQL - Creating a stored procedure with multiple optional parameters

  25. 25

    ArgumentException on Adding multiple Parameters in Stored Procedure

  26. 26

    Sending multiple parameters to stored procedure with jQuery Ajax

  27. 27

    How to pass parameters to a procedure in assembly?

  28. 28

    How to return multiple resultset from a stored procedure using cte?

  29. 29

    PDO stored procedure call

HotTag

Archive