开发者

Pear MDB2 class and raiserror exceptions in SQL Server

开发者 https://www.devze.com 2022-12-29 06:03 出处:网络
in SQL Server it\'s possible to raise an error with raiserror(). I want to use a severity, which doesn\'t interrupt the connection. This error is raised in a stored procedure. In SQL Management Studio

in SQL Server it's possible to raise an error with raiserror(). I want to use a severity, which doesn't interrupt the connection. This error is raised in a stored procedure. In SQL Management Studio all is fine and I get my error code when executing this SP. But when trying to execute this SP via MDB2 in PHP5 this doesn't work. All I get is an empty array.

MDB2 object is created via (including needed options):

$db =& MDB2::connect($dsn);
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
$db->setOption('portability',MDB2_PORTABILITY_ALL ^ MDB2_PORTABILIT开发者_高级运维Y_EMPTY_TO_NULL);

The following works (I get a PEAR error):

$db->query("RAISERROR('test',11,0);");

But when calling a stored procedure which raises this error via

$db->query("EXEC sp_raise_error");

there is not output. What's wrong?


Verify the returned result objects via

$res = $db->query(..)
if (MDB2::isError($res)) {
    echo $res->getMessage() . "\n" . $res->getUserInfo();
    die();
}

See http://pear.php.net/manual/en/package.database.mdb2.intro-fetch.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号