Jump to content

[SOLVED] Running a stored procedure on mssql


Recommended Posts

I have pear mdb2 module installed on my php sandbox.


I am trying to run a stored procedure and cant get it to work. I get a blank page. The stored procedure it self is fine, since I can use it in sql query analyser.


I have searched the net and found the following code.


require_once 'MDB2.php';

$dsn = array(
    'phptype'  => 'mssql',
    'username' => $_POST['user'],
    'password' => $_POST['pass'],
    'hostspec' => $_POST['host'],
    'database' => $_POST['db'],

$options = array(
    'debug'       => 2,
    'portability' => MDB2_PORTABILITY_ALL,

$mdb2 =& MDB2::connect($dsn, $options);
if (PEAR::isError($mdb2)) {
    die($mdb2->getMessage(). ', ' . $mdb2->getDebugInfo());

echo "Connected!";

$sth = $mdb2->prepare("exec getItem") or die($sth->getMessage(). ', ' . $sth->getDebugInfo());

$bindvars = array("id" => 'a123',
			"count" => 8,
			"location" => 'system');
$res=$mdb2->execute($sth,$bindvars)or die($res->getMessage(). ', ' . $res->getDebugInfo());
echo $result;



I can connect to db without any issues, I just cant run the stored procedure.


Thank you!

Link to comment
Share on other sites

  • 1 month later...


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.