时间:2021-05-26
核心代码:
<?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(); }}?>下面说下调用
function __autoload($MssqlUtil) { require $MssqlUtil.'.php'; } $db = new MssqlUtil($config['host'],$config['user'],$config['keys'],$config['base']);主要说下带参数的存储过程调用
select * from t2 where t2.id in(select max(t2.id) from t1 join t2 on t1.id = t2.pid group by t1.id);
取每个分类的最新一条数据。此处做个记录。
t1为类别表,t2为主表
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
存储过程简介为什么要用存储过程?MySQL5.0版本开始支持存储过程。大多数SQL语句都是针对一个或多个表的单条语句。并非所有的操作都那么简单。经常会有一个完整
MySQL5.0版本开始支持存储过程。存储过程(StoredProcedure)是一种在数据库中存储复杂程序,以便外部程序调用的一种数据库对象。存储过程是为了完
本文实例讲述了PHP使用PDO调用mssql存储过程的方法。分享给大家供大家参考,具体如下:数据库中已创建存储过程user_logon_check,PHP调用示
本文实例讲述了PHP+Redis开发的书签案例。分享给大家供大家参考,具体如下:redis是一个key-value存储系统。和Memcached类似,它支持存储
复制代码代码如下:如果实现了PHP和MySQL链接了,PHP和MSSQL的链接其实很简单;支持MSSQL的本地链接和远程链接,以本地链接为例:机器上安装了MSS