我有一个使用预定义的mssql连接调用mssql存储过程的函数。基础是我有一个类来执行与mssql数据库的连接,并将该连接分配给变量。这个类中有另一个函数,然后调用一个单独的类(我在下面包含了这个单独的类)。然后,该类定义mssql变量以传递连接,以便它可用于几个存储过程。
此类'IssueCertificate'中的第一个函数正常工作并且存储过程运行正常,此函数然后调用另一个名为PrintCertificate的类中的函数,此函数然后调用另一个失败的存储过程。我已经尝试过这个函数作为一个独立的类外部,它运行正常所以这里没有问题,但由于某些原因,当它作为另一个函数的一部分运行时,它失败了。请参阅下面的课程:
$_SERVER['DOCUMENT_ROOT'] = str_replace('\\','/',substr($_SERVER['SCRIPT_FILENAME'], 0,
0-strlen($_SERVER['PHP_SELF'])));
define("BASEURL", $_SERVER['DOCUMENT_ROOT']);
require_once(BASEURL."/api/db.php");
require_once(BASEURL."/api/adodb/adodb.inc.php");
require_once(BASEURL."/api/functions.php");
require_once(BASEURL."/api/modules/print.class.php");
require_once(BASEURL."/common/dbconnect.php");
date_default_timezone_set('GMT');
class CertificatesDirectAPI {
var $data = '';
function __construct($data, $config) {
$this->data['Request'] = $data;
// create connection to the database
$this->db = ADONewConnection('mysql');
// if connection failed, send error response xml, otherwise continue processing
if (!$this->db->connect($config['db']['hostname'],$config['db']['username'],$config['db']['password'],$config['db']['database'])) {
$this->db->close();
exit();
}
$this->msdb = mssql_connect('server','user','password');
mssql_select_db('database');
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->process();
}
// process the request
private function process() {
$output = $this->PrintCertificate();
}
private function PrintCertificate(){
//get supplier info
$installer = new UserInformation($this->msdb);
$supplier = $installer->GetInstallerDetails($this->data['Request']['installer_id']);
//create new instance and print
$cert = new PrintCert($this->msdb);
$response = $cert->IssueCertificate($this->data,$supplier);
}
}
$api = new CertificatesDirectAPI($_REQUEST, $config);
class PrintCert {
public $msdb;
function __construct($msdb){
//assign class wide vars to object
$this->msdb = $msdb;
}
public function IssueCertificate($data, $supplier){
$return = $this->PrintCertificate("1279441", $supplier);
return $return;
}
private function PrintCertificate($certNumber, $supplier){
//initiate function
$proc = mssql_init('usp_Return_Certificate_Details', $this->msdb);
mssql_bind($proc, '@Certificate_Number', $certNumber, SQLINT4, false, false, 10);
//Execute Procedure
$result = mssql_execute($proc);
while ($row = mssql_fetch_assoc($result)){
$results[] = $row;
}
$return = $results;
//print_r($return);
$pdf = $this->BuildPdf($return[0], $supplier);
//Free Memory
mssql_free_statement($proc);
return $pdf;
}
}
返回的错误消息如下:
Warning: mssql_execute() [function.mssql-execute]: stored procedure execution failed in /home/ssaibuk/public_html/api/modules/print.class.php on line 131
Warning: mssql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/ssaibuk/public_html/api/modules/print.class.php on line 133
如果这里有足够的东西让我知道,我可以添加更多。