Php,Mssql,操作简单,封装,支持,存储,过程,复制,代码,如下,php,class,Mssql,time,200
后端开发-php教程
asp 网店源码,vscode左边没有安装插件,ubuntu安装共享,手机怎么连上tomcat,爬虫的资料,php是软件吗,图文收录seo正式版,网站源码大小,php商城系统模板免费下载lzw
<?php
/*
* class :Mssql
* time :2009-12-10
* author :Libaochang
* version :1.0b
* description :mssql database access class,it can execute the procedur or sql
*/
class MssqlUtil
{
var $user = null; //database user name
var $keys = null; //database user password
var $host = 'localhost'; //database host name/ip and port
var $base = null; //database name
var $link = null; //create link
/**
* construct function init all parmeters
* @param $host database host name/ip and port
* @param $user database user name
* @param $keys database user password
* @param $base database name
*/
function __construct($host,$user,$keys,$base)
{
$this->host = $host;
$this->user = $user;
$this->keys = $keys;
$this->base = $base;
}
/**
* create the connection
*/
function connect()
{
$this->link = mssql_connect($this->host,$this->user,$this->keys);
if(!$this->link)
{
die('connecting failed...check the module and setting...');
}
$select = mssql_select_db($this->base,$this->link);
if(!$select)
{
die('data base is not exist...,please checke it ...');
}
}
/**
* execute the procedur width the parameter
* @param $pName procedur name
* @param $parName parameters it's like this $par=array('@a'=>'a')
* @param $sqlTyle the procedur's parameter type, it's llike this $sqlType=array(SQLVARCHAR,SQLVARCHAR); and there is not the char single quote mark(').
* @return object array
*/
function executeProcedur($pName,$parName,$sqlTyle)
{
$this->connect();
$stmt = mssql_init($pName,$this->link);
if(isset($parName))
{
$i = 0;
foreach($parName as $par=>$value)
{
mssql_bind($stmt,$par,$value,$sqlTyle[$i]);
++$i;
}
$res = mssql_execute($stmt);
$this->close();
while($row=mssql_fetch_assoc($res))
{
$r[] = $row;
}
unset($i);
mssql_free_result($res);
mssql_free_statement($stmt);
return $r;
}
}
/**
* execute procedur without the parameter
* @param $pName Procedur Name
* @return object array
*/
function executeProcedurNoPar($pName)
{
$this->connect();
$stmt = mssql_init($pName,$this->link);
$res = mssql_execute($stmt);
$this->close();
while($row=mssql_fetch_assoc($res))
{
$r[] = $row;
}
mssql_free_result($res);
mssql_free_statement($stmt);
return $r;
}
/**
* Get one row return Array
* @param $sql
* @return Array
*/
function getRowArray($sql)
{
$res = $this->query($sql);
$r = mssql_fetch_row($res);
mssql_free_result($res);
return $r;
}
/**
* Get one row return object
* @param $sql Sql
* @return Object
*/
function getRowObject($sql)
{
$res = $this->query($sql);
$r = mssql_fetch_assoc($res);
return $r;
}
/**
* Execute one sql
* @param $sql Sql
* @return result
*/
function query($sql)
{
$this->connect();
$res = mssql_query($sql,$this->link);
$this->close();
return $res;
}
/**
* Get every row from result by Object, Return a Array with every element is Object
* @param $sql
* @return Object Array result
*/
function getResult($sql)
{
$res = $this->query($sql);
while($row=mssql_fetch_assoc($res))
{
$r[] = $row;
}
unset($row);
mssql_free_result($res);
return $r;
}
/**
* execute a sql
* @param $sql Sql
*/
function executeSql($sql)
{
return $this->query($sql);
}
/**
* execute a sql statement
* @param $sql
* @return int $affected rows
*/
function querySql($sql)
{
$this->connect();
mssql_query($sql,$this->link);
$affected = mssql_rows_affected($this->link);
$this->close();
return $affected;
}
/**
* close connection
*/
function close()
{
mssql_close();
}
}
?>