Php Mssql操作简单封装支持存储过程操作简单封装支持存储过程
没有啥太多的功能,就是简单封装,也没有缓存,平时用ezSQL,但是ezSQL不支持存储过程,所以这里封装了存储过
程,因为自己的需要,只是做一个标记在这里而已。
核心代码:
<?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 <type> $host database host name/ip and port
* @param <type> $user database user name
* @param <type> $keys database user password
* @param <type> $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 <type> $pName procedur name
* @param <type> $parName parameters it's like this $par=array('@a'=>'a')
* @param <type> $sqlTyle the procedur's parameter type, it's llike this $sqlType=array(SQLVARCHAR,SQLVARCHAR); and there is not the char single quote mark(').
* @return <type> 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 <type> $pName Procedur Name
* @return <type> 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)) {
评论0
最新资源