Php Mssql操作簡(jiǎn)單封裝支持存儲(chǔ)過(guò)程
核心代碼:
<?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)) { $r[] = $row; } mssql_free_result($res); mssql_free_statement($stmt); return $r; } /** * Get one row return Array * @param <type> $sql * @return <type> 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 <type> $sql Sql * @return <type> Object */ function getRowObject($sql) { $res = $this->query($sql); $r = mssql_fetch_assoc($res); return $r; } /** * Execute one sql * @param <type> $sql Sql * @return <type> 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 <type> $sql * @return <type> 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 <type> $sql Sql */ function executeSql($sql) { return $this->query($sql); } /** * execute a sql statement * @param <type> $sql * @return <type> 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(); } } ?>
下面說(shuō)下調(diào)用
function __autoload($MssqlUtil) { require $MssqlUtil.'.php'; } $db = new MssqlUtil($config['host'],$config['user'],$config['keys'],$config['base']);
主要說(shuō)下帶參數(shù)的存儲(chǔ)過(guò)程調(diào)用
$pName 存儲(chǔ)過(guò)程名字 $parName 參數(shù),參數(shù)形式很重要,是數(shù)組類型,對(duì)應(yīng)關(guān)系為 array('@a'=>'a') @a 為存儲(chǔ)過(guò)程里面的參數(shù),a為要傳遞的值 $sqlTyle 是存儲(chǔ)過(guò)程參數(shù)的數(shù)據(jù)類型,是數(shù)組形式,也很重要 array(SQLCHAR,SQLVARCHAR),注意不要加單引號(hào)等,因?yàn)镾QLVARCHAR是SQL的一些常量 帶參數(shù)存儲(chǔ)過(guò)程 $db->executeProcedur($pName,$parName,$sqlTyle); 無(wú)參數(shù)存儲(chǔ)過(guò)程 $db->executeProcedurNoPar($pName);
select * from t2 where t2.id in(select max(t2.id) from t1 join t2 on t1.id = t2.pid group by t1.id);
取每個(gè)分類的最新一條數(shù)據(jù)。此處做個(gè)記錄。
t1為類別表,t2為主表
- PHP訪問(wèn)MYSQL數(shù)據(jù)庫(kù)封裝類(附函數(shù)說(shuō)明)
- PHP數(shù)據(jù)庫(kù)表操作的封裝類及用法實(shí)例詳解
- PHP封裝的數(shù)據(jù)庫(kù)保存session功能類
- PHP中對(duì)數(shù)據(jù)庫(kù)操作的封裝
- php基于單例模式封裝mysql類完整實(shí)例
- php封裝的mysqli類完整實(shí)例
- php mysql 封裝類實(shí)例代碼
- PHP封裝的MSSql操作類完整實(shí)例
- php封裝的連接Mysql類及用法分析
- php實(shí)現(xiàn)mysql封裝類示例
- php中mysql模塊部分功能的簡(jiǎn)單封裝
- php封裝的數(shù)據(jù)庫(kù)函數(shù)與用法示例【參考thinkPHP】
相關(guān)文章
基于PHP實(shí)現(xiàn)堆排序原理及實(shí)例詳解
這篇文章主要介紹了基于PHP實(shí)現(xiàn)堆排序原理及實(shí)例詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06PHP實(shí)現(xiàn)單文件、多個(gè)單文件、多文件上傳函數(shù)的封裝示例
這篇文章主要介紹了PHP實(shí)現(xiàn)單文件、多個(gè)單文件、多文件上傳函數(shù)的封裝,結(jié)合實(shí)例形式詳細(xì)分析了php文件上傳的原理及針對(duì)文件上傳函數(shù)的封裝相關(guān)操作技巧,需要的朋友可以參考下2019-09-09js基于qrcode.js生成二維碼的方法【附demo插件源碼下載】
這篇文章主要介紹了js基于qrcode.js生成二維碼的方法,結(jié)合實(shí)例形式分析了基于qrcode.js文件生成二維碼的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-12-12PHP利用緩存處理用戶注冊(cè)時(shí)的郵箱驗(yàn)證,成功后用戶數(shù)據(jù)存入數(shù)據(jù)庫(kù)操作示例
這篇文章主要介紹了PHP利用緩存處理用戶注冊(cè)時(shí)的郵箱驗(yàn)證,成功后用戶數(shù)據(jù)存入數(shù)據(jù)庫(kù)操作,涉及PHP操作Memcache緩存驗(yàn)證登錄與數(shù)據(jù)庫(kù)寫入相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-12-12學(xué)習(xí)php設(shè)計(jì)模式 php實(shí)現(xiàn)合成模式(composite)
這篇文章主要介紹了php設(shè)計(jì)模式中的合成模式,使用php實(shí)現(xiàn)合成模式,感興趣的小伙伴們可以參考一下2015-12-12PHP 日,周,月點(diǎn)擊排行統(tǒng)計(jì)
原理就是先判斷當(dāng)前文章的日期是否為當(dāng)月當(dāng)日當(dāng)周的,是就點(diǎn)擊數(shù)加12012-01-01