Jump to content

[SOLVED] Running a stored procedure on mssql


darksniperx

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.

 

<?php
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());
$result=$res->fetchRow()[0];
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 thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.