0

In PHP5 I used to bind Params like this:

mssql_bind($stmt,'@BIAC_MEMBER',$inMemberID,SQLVARCHAR); //Input mssql_bind($stmt,'@BIAC_RESULT',$outResult,SQLVARCHAR,true); //Output

Since mssql_* got removed in PHP7 and you need to work with PDO now I changed my connection to this:

$stmt = $conn->prepare("CALL MyStoredProc(?, ?, ?, ?)");

According to the PHP doc you can bind using $stmt->bindParam(); but they have not mentionened if and how you can bind input aswell as output params.

Is it possible to specify multiple in-/output params, and if so, how?

2 Answers 2

1

You can specify your params following the documentation pages :

http://php.net/manual/en/pdo.prepared-statements.php

http://php.net/manual/en/pdostatement.bindparam.php

Namely using the following code :

<?php
$stmt = $dbh->prepare("CALL MyStoredProc(?, ?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000);
$value = 'hello';
$stmt->bindParam(2, $value, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000); 

// call the stored procedure
$stmt->execute();

print "procedure returned $return_value\n & $value";
?>

This has one out parameter and one in/out paramater, so should be easily adaptable for your needs. They key is simply to setting the correct data_type and length value( arguments 3 & 4 in bindParam() )

Full list of datatypes:

http://php.net/manual/en/pdo.constants.php

Note: this is taken from docs and adapted, but I Haven't tested it, but hopefully at the very least it sets you in the right direction.

Sign up to request clarification or add additional context in comments.

Comments

0

In PDO you can use bindParam. Here's a full example of how to use bindParam. https://www.ibm.com/support/knowledgecenter/SSSNY3_10.1.0/com.ibm.swg.im.dbclient.php.doc/doc/t0023502.html

Good Luck!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.