FreeBSD下使用SQL Server2005(2008)須要使用FreeTDS。sql
安裝FreeTSD後,使用PHP語言進行測試。在使用mssql_execute調用存儲過程時出現以下錯誤:數據庫
Warning: mssql_execute():stored procedure execution failed in...測試
語法以下:fetch
...spa
$sp1=mssql_init('uspUserGetPoints_byID',$t_dbconn);.net
$userid=11360;ci
$account='cp';get
$points=0;//outputit
mssql_bind($sp1,'@UserID ',$userid,SQLINT2);io
mssql_bind($sp1,'@Account ',$account,SQLCHAR,false,false,2);
mssql_bind($sp1,'@Points',$points,SQLINT2,TRUE);
$result=mssql_execute($sp1,true);
...
注:uspUserGetPoints_byID是存儲過程名,包括2個輸入參數1個輸出參數,有返回值
查找資料聽說須要修改freetds.conf,增長以下內容:
[open119]
host = xxx.xxx.xxx.xxx
port = 1433
tds version = 8.0
修改後問題依舊...
最後只好嘗試另外一種調用存儲過程的方法,語法以下:
...
$query = "declare @Result INT\n";
$query .= "declare @Points INT\n";
$query .= "exec @Result=uspUserGetPoints_byID $userid,'$account',@Points OUTPUT\n";
$query .= "select @Result as Result,@Points as Points\n";
//執行存儲過程
$result=mssql_query($query) or die("Error");
$row=mssql_fetch_array($result);
echo $row['Result'];
echo '<br>';
echo $row['Points'];
...
運行成功。
附鏈接數據庫代碼:
$DatabaseHost='172.54.88.52:1433';
$DatabaseName='testDB';
$DatabaseUser='test1';
$DatabasePwd='123456';
$t_dbconn=mssql_connect($DatabaseHost,$DatabaseUser,$DatabasePwd);
if(!$t_dbconn)
{
$tr[0][0]=1;
echo $tr[0][0];
exit();//鏈接數據庫失敗
}
//echo "connect ok!";
$dbobject=mssql_select_db('ompay2',$t_dbconn);
if(!$dbobject)
{
echo 'db is not ok';
exit();
}
附SQL使用的參數定義代碼以下:
//if(!defined('dbMSSQL_Types'))
//{
// define('dbMSSqlTypes',1);
// $MSSQL_types[127] = SQLINT4; /* bigint*/
// $MSSQL_types[104] = SQLBIT; /* bit*/
// $MSSQL_types[175] = SQLCHAR; /* char*/
// $MSSQL_types[56] = SQLINT2; /* int*/
// $MSSQL_types[52] = SQLINT2; /* smallint*/
// $MSSQL_types[35] = SQLTEXT; /* text*/
// $MSSQL_types[48] = SQLINT1; /* tinyint*/
// $MSSQL_types[167] = SQLVARCHAR; /* varchar*/
// $MSSQL_types[62] = SQLFLT8; /* float*/
// $MSSQL_types[173] = SQLVARCHAR; /* binary*/ // Adaptation
// $MSSQL_types[61] = SQLINT4; /* datetime*/ // Adaptation
// $MSSQL_types[106] = SQLFLT8; /* decimal*/ // Adaptation
// $MSSQL_types[34] = SQLVARCHAR; /* image*/ // Adaptation
// $MSSQL_types[60] = SQLFLT8; /* money*/ // Adaptation
// $MSSQL_types[239] = SQLCHAR; /* nchar*/ // Adaptation
// $MSSQL_types[99] = SQLTEXT; /* ntext*/ // Adaptation
// $MSSQL_types[108] = SQLFLT8; /* numeric*/ // Adaptation
// $MSSQL_types[231] = SQLVARCHAR; /* nvarchar*/ // Adaptation
// $MSSQL_types[59] = SQLFLT8; /* real*/ // Adaptation
// $MSSQL_types[58] = SQLINT4; /* smalldatetime*/ // Adaptation
// $MSSQL_types[122] = SQLFLT8; /* smallmoney*/ // Adaptation
// $MSSQL_types[98] = SQLVARCHAR; /* sql_variant*/ // Adaptation
// $MSSQL_types[189] = SQLINT4; /* timestamp*/ // Adaptation
// $MSSQL_types[165] = SQLVARCHAR; /* varbinary*/ // Adaptation
//}