• PHP操作MSSql


    <?php
     if (!defined('BASEPATH')) exit('No direct script access allowed'); 
        /*****PHP操作SqlServer数据库********/
        class  Sqlsrv
        {
            private $hostname="JKT-001SQLEXPRESS";
            private $username="sa";
            private $password="52ebook";
            private $dbname="enterprise";
            private $conn;
            function __construct()
                {
                    try{
                    $constr=array("Database"=>$this->dbname,"CharacterSet" => "UTF-8","UID"=>$this->username,"PWD"=>$this->password);
                    
                    $this->conn=sqlsrv_connect($this->hostname,$constr);
                    
                    if($this->conn==false)
                    {
                        print_r(sqlsrv_errors(),true);
                        die;
                    }
                    
                    }catch(Exception $ex)
                    {
                        echo $ex->getMessage();
                    }
                }
            /*查询所有数据*/
            public function QuaryAll($sql)
            {
                try{
                $rs=sqlsrv_query($this->conn,$sql);
                $result=array();
                while($row = sqlsrv_fetch_array($rs,SQLSRV_FETCH_NUMERIC))
                {
                    $result[]=$row;
                }
                sqlsrv_free_stmt($rs);
                return $result;
                }catch(Exception $ex)
                {
                    echo $ex->getMessage();
                }
            }
            /*执行sql语句,返回所影响的行数*/
            public function AffectedRows($sql)
            {
                try{
                $rs=sqlsrv_query($this->conn,$sql);
                $result=sqlsrv_rows_affected($rs);
                sqlsrv_free_stmt($rs);
                return $result;
                }catch(Exception $ex)
                {
                    echo $ex->getMessage();
                }
            }
            
            /**
            实现分页查询*
            *@tablename 表名
            *@columns    字段列表
            *@pagenum    当前页码
            *@pagecount    页面条数
            *@prikey    分页主键
            *@orderkey    排序主键
            */
            public function QueryPage($tablename,$columns='*',$pagenum=20,$pagecount=1,$prikey,$orderkey)
            {
                try{
                $columnnames='*';
                if(is_array($columns))
                {
                    $columnnames=implode(',',$columns);
                }
                $sql='select top '.$pagenum.' '.$columnnames.' from '.$tablename.' where '.$prikey.' not in (select top '.$pagenum*($pagecount-1).' '.$prikey.' from '.$tablename.' order by '.$orderkey.') order by '.$orderkey;
                $rs=sqlsrv_query($this->conn,$sql);
                $result=array();
                while($row = sqlsrv_fetch_array($rs,SQLSRV_FETCH_NUMERIC))
                {
                    $result[]=$row;
                }
                sqlsrv_free_stmt($rs);
                return $result;
                }catch(Exception $ex)
                {
                    echo $ex->getMessage();
                }
            }
            function __destruct()
            {
                sqlsrv_close($this->conn);
            }
        }
  • 相关阅读:
    蒙版
    雪碧图
    用html来设置一个用户登录网页
    用vs来实现反序输出的效果
    用vs来写一段判断是不是水仙花数的代码
    Node.js使用Sequelize操作MySQL
    修改 xampp 默认端口号
    TCP/IP详解学习笔记(1)基本概念
    CSS常用标签
    Linux 系统中 sudo 命令的 10 个技巧
  • 原文地址:https://www.cnblogs.com/zhaobijin/p/5813318.html
Copyright © 2020-2023  润新知