本文共 1692 字,大约阅读时间需要 5 分钟。
$MSSQL_SERVER="localhost";
$connectionInfo = array( "Database"=>"DBNAME", "UID"=>"sa", "PWD"=>"123456");/*********************/
/* */
/* Version : 5.1.0 */
/* Author : RM */
/* Comment : ms_conn.php */
/* */
/*********************/
//MSSQL连接部分
function open_mssqlconn( )
{
global $mssql_connection;
include_once( "oa_config.php" );
if (!$mssql_connection){
$mssql_link=sqlsrv_connect( $MSSQL_SERVER, $connectionInfo);
if (!$mssql_link){
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
return $mssql_link;
} else {
return $mssql_connection;
}
}
//SQL查询
function mssqlquery($Q)
{
if (!$mssql_connection){
$mssql_connection=open_mssqlconn();
}
$cursor=sqlsrv_query($mssql_connection,$Q);
if ( !$cursor )
{
echo "SQL查询出错.\n";
die( print_r( sqlsrv_errors(), true));
}
return $cursor;
}
//执行SQL
function mssqlexec($Q){
$stmt = sqlsrv_prepare( $mssql_connection, $Q);
if( $stmt===false )
{
echo "SQL预编译出错.\n";
return false;
die( print_r( sqlsrv_errors(), true));
}
/* Execute the statement. Display any errors that occur. */
if( sqlsrv_execute( $stmt)===false)
{
echo "执行SQL出错.\n";
return false;
die( print_r( sqlsrv_errors(), true));
}
/* Free the statement and connection resources. */
sqlsrv_free_stmt($stmt);
return true;
}
if (!$mssql_connection)
{
$mssql_connection=open_mssqlconn();
}调用写封装好的方法:
//获取存货名称
public function getcinvname(){
$cinvcode=iconv("UTF-8","GBK", $_POST["cinvcode"]);
$query="select cinvname from inventory where cinvcode='{$cinvcode}'";
$cursor=mssqlquery($query);
$cinvname='';
while($ROW=sqlsrv_fetch_array($cursor,SQLSRV_FETCH_ASSOC)){
$cinvname=iconv("GBK","UTF-8",$ROW["cinvname"]);
}
sqlsrv_free_stmt($cursor);
$this->returnajax(0,$cinvname);
}
转载地址:https://blog.csdn.net/weixin_33758343/article/details/116166697 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!