1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php mssql server 数据库连接类

php mssql server 数据库连接类

时间:2019-01-03 23:19:08

相关推荐

php mssql server 数据库连接类

数据库|mysql教程

php,mssql,server,,数据库,

数据库-mysql教程

mssql server 连接类

class msDriver{

public $error;

public $querynum=0;

public $link;

public $lastQuery;

public $lastInsert_id=0;

public $error_callback=array(‘record’); //record,ignore,report,abort

public $error_report_file=ROOT.”/webdata/db.error.log”;

function __construct($server=”,$connectionInfo=array()){

if ($server){

$this->connect($server,$connectionInfo);

}

}

function __destruct(){

!$link && $link= &$this->link;

if ($link) sqlsrv_close( $link );

}

function connect($dbhost=(local)’, $connectionInfo=array()){

$this->link=sqlsrv_connect($dbhost,$connectionInfo);

if (!$this->link) $this->halt();

}

/**

*查询过程

*

* @param string $sql

* @param resource $link

* @return resource

*/

function query($sql=””,$link=”){

!$link && $link= &$this->link;

);

$this->lastQuery=&$query;

if (!$query) $this->halt();

$reg = “#insert into#”;

if(preg_match($reg,$sql)){

$res = sqlsrv_query($link,”select @@IDENTITY as id”);

$this->lastInsert_id = sqlsrv_get_field($res,0);

}

return $query;

}

/**

* 返回字段总数

*

* @param resource $result

* @return number

*/

function num_fields($result=”){

if (!$result) $this->halt();

return @sqlsrv_num_fields($result);

}

/**

* 返回字段值

*

* @param resource $result

* @param Int $fieldIndex

* @return value

*/

function result($result=”,$fieldIndex=0){

if (!$result) $this->halt();

return sqlsrv_get_field($result,$fieldIndex);

}

/**

* 返回行数组

*

* @param unknown_type $result

* @return unknown

*/

function fetch_array($result,$type=SQLSRV_FETCH_ASSOC){ //SQLSRV_FETCH_NUMERIC,SQLSRV_FETCH_ASSOC,SQLSRV_FETCH_BOTH

!$result && $result=$this->lastQuery;

if (!$result) $this->halt();

);

return is_array($r)?$r:0;

}

/**

* 返回影响的记录数

*

* @param resource $result

* @return number

*/

function affected_rows($result) {

if (!$result) $this->halt();

return sqlsrv_rows_affected($result);

}

function insert_id(){

return $this->lastInsert_id;

}

function freeResult($result){

!$result && $result=$this->lastQuery;

sqlsrv_free_stmt($result);

}

/**

* 错误的处理方式

*

*/

function halt(){

$err=$this->getEroor();

//var_dump($err[”]);

if (in_array(‘record’,$this->error_callback)){

$fp=fopen($this->error_report_file,’a+’);

if ($fp){

fwrite($fp,”[“.date(“Y//m/dH:i:s”).”](“.$err[‘code’].”)”.$err[‘message’].”,URL:”.$_SERVER[“REQUEST_URI”].”?”.$_SERVER[“QUERY_STRING”].”rn”);

fclose($fp);

}

}

if (in_array(‘report’,$this->error_callback)){

echo “

错误:[“.date(“Y//m/d H:i:s”).”](“.$err[‘code’].”)”.$err[‘message’];

}

if (in_array(‘abort’,$this->error_callback)){

exit;

}

}

/**

* 返回查询错误

*

* @return array

*/

function getEroor(){

$err=sqlsrv_errors();

//return array(‘code’=>$err[‘code’],’message’=>$err[‘message’]);

return is_array($err)?$err[0]:array();

}

apache源码安装步骤,ubuntu 省电优化,tomcat打开默认首页,通辽爬虫网吧,开源微信接口php源码,哪种公司适合用seo优化做推广lzw

}

传奇登录器源码,vscode固定横滚动条,ubuntu办公电脑,tomcat端口冲突修改,python指令爬虫,php表单怎么写,海南抖音seo获客系统,竖排导航网站lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。