sqlsrv.class.php 一个 php 连接 sql server的类
程序员文章站
2022-05-13 10:20:35
...
sqlsrv.class.php 一个 php 连接 sql server的类
sqlsrv.class.php
<?php /** * @desc A simple and convenient php sqlsrv class * @author Yaseng WwW.Yaseng.Me [Yaseng@UAUC.NET] * @link http://yaseng.me/sqlsrv-class.html */ class sqlsrv{ var $error_log = array(); var $sql_log = array(); var $query_id; var $num_rows; var $conn; //connection function sqlsrv($server, $user, $pass, $dbname) { $this->conn = @sqlsrv_connect($server, array('UID' => $user ,'PWD'=> $pass, 'Database' => $dbname)); if($this->conn === false) { $this->error_log[] = sqlsrv_errors(); die(); } } //query source function query($sql){ $stmt = sqlsrv_query($this->conn, $sql); $this->sql_log[] = $sql; if($stmt === false) { $this->error_log[] = sqlsrv_errors(); } else { $this->query_id = $stmt; $this->num_rows = $this->affectedRows(); } } //fetch data function fetch_all($sql) { $this->query($sql); $data = array(); while($row = @sqlsrv_fetch_array($this->query_id, SQLSRV_FETCH_ASSOC)) { $data[] = $row; } return $data; } // $DB->count(select * from users) function fetch_one($sql){ $this->query($sql); return sqlsrv_fetch_array($this->query_id, SQLSRV_FETCH_ASSOC); } // $DB->count(select count(*) from users) function count($sql){ $count=$this->fetch_one($sql); return $count[""]; } function affectedRows() { return ($this->query_id) ? @sqlsrv_num_rows($this->query_id) : false; } } ?>
2. [代码]测试
count($strsql)); echo "sql:"; print_r($sql->sql_log); echo "errors:"; print_r($sql->error_log); echo "sqlsrv:"; print_r($sql); ?>
3. [图片] 4FC8ADB91A2746089187E5DD909222E2.jpg
推荐阅读
-
php使用sql server验证连接数据库的方法
-
PHP连接SQL Server的方法分析【基于thinkPHP5.1框架】
-
php入门之连接mysql数据库的一个类_PHP
-
依照步骤做的,php仍然不能连接到SQL Server2005 ?
-
从360提供的PHP防SQL注入代码改成的一个类
-
在Navicat premium上创建的SQL Server数据库,实现用PHP连接(即php连接微软MSSQL),navicatpremium_PHP教程
-
php使用sql server验证连接数据库的方法
-
sqlsrv.class.php 一个 php 连接 sql server的类
-
Linux下PHP连接SQL Server的办法
-
64位IIS7下的PHP 5.4配置及如何连接SQL Server 2008