


This article mainly introduces the MSSql operation class encapsulated by PHP, and analyzes various commonly used mssql database operations encapsulated by PHP in the form of complete examples, including the connection, addition, deletion, modification, and query for mssql database. Friends who need it can For reference,
is as follows:
<?php /*MSSql的操作类*/ class MSSql { var $link; var $querynum = 0; /*连接MSSql数据库,参数:dbsn->数据库服务器地址,dbun->登陆用户名,dbpw->登陆密码,dbname->数据库名字*/ function Connect($dbsn, $dbun, $dbpw, $dbname) { if($this->link = @mssql_connect($dbsn, $dbun, $dbpw, true)) { $query = $this->Query('SET TEXTSIZE 2147483647'); if (@mssql_select_db($dbname, $this->link)) { } else { $this->halt('Can not Select DataBase'); } } else { $this->halt('Can not connect to MSSQL server'); } } /*执行sql语句,返回对应的结果标识*/ function Query($sql) { if($query = @mssql_query($sql, $this->link)) { $this->querynum++; return $query; } else { $this->querynum++; $this->halt('MSSQL Query Error', $sql); } } /*执行Insert Into语句,并返回最后的insert操作所产生的自动增长的id*/ function Insert($table, $iarr) { $value = $this->InsertSql($iarr); $query = $this->Query('INSERT INTO ' . $table . ' ' . $value . '; SELECT SCOPE_IDENTITY() AS [insertid];'); $record = $this->GetRow($query); $this->Clear($query); return $record['insertid']; } /*执行Update语句,并返回最后的update操作所影响的行数*/ function Update($table, $uarr, $condition = '') { $value = $this->UpdateSql($uarr); if ($condition) { $condition = ' WHERE ' . $condition; } $query = $this->Query('UPDATE ' . $table . ' SET ' . $value . $condition . '; SELECT @@ROWCOUNT AS [rowcount];'); $record = $this->GetRow($query); $this->Clear($query); return $record['rowcount']; } /*执行Delete语句,并返回最后的Delete操作所影响的行数*/ function Delete($table, $condition = '') { if ($condition) { $condition = ' WHERE ' . $condition; } $query = $this->Query('DELETE ' . $table . $condition . '; SELECT @@ROWCOUNT AS [rowcount];'); $record = $this->GetRow($query); $this->Clear($query); return $record['rowcount']; } /*将字符转为可以安全保存的mssql值,比如a'a转为a''a*/ function EnCode($str) { return str_replace(''', '''', str_replace('', '', $str)); } /*将可以安全保存的mssql值转为正常的值,比如a''a转为a'a*/ function DeCode($str) { return str_replace('''', ''', $str); } /*将对应的列和值生成对应的insert语句,如:array('id' => 1, 'name' => 'name')返回([id], [name]) VALUES (1, 'name')*/ function InsertSql($iarr) { if (is_array($iarr)) { $fstr = ''; $vstr = ''; foreach ($iarr as $key => $val) { $fstr .= '[' . $key . '], '; $vstr .= ''' . $val . '', '; } if ($fstr) { $fstr = '(' . substr($fstr, 0, -2) . ')'; $vstr = '(' . substr($vstr, 0, -2) . ')'; return $fstr . ' VALUES ' . $vstr; } else { return ''; } } else { return ''; } } /*将对应的列和值生成对应的insert语句,如:array('id' => 1, 'name' => 'name')返回[id] = 1, [name] = 'name'*/ function UpdateSql($uarr) { if (is_array($uarr)) { $ustr = ''; foreach ($uarr as $key => $val) { $ustr .= '[' . $key . '] = '' . $val . '', '; } if ($ustr) { return substr($ustr, 0, -2); } else { return ''; } } else { return ''; } } /*返回对应的查询标识的结果的一行*/ function GetRow($query, $result_type = MSSQL_ASSOC) { return mssql_fetch_array($query, $result_type); } /*清空查询结果所占用的内存资源*/ function Clear($query) { return mssql_free_result($query); } /*关闭数据库*/ function Close() { return mssql_close($this->link); } function halt($message = '', $sql = '') { $message .= '<br />MSSql Error:' . mssql_get_last_message(); if ($sql) { $sql = '<br />sql:' . $sql; } exit("DataBase Error.<br />Message $message $sql"); } } ?>##Summary: The above is the entire content of this article, I hope it can help Everyone’s learning helps. Related recommendations:
Summary of three commonly used design patterns in PHP
PHP MySQL implements input page number to jump to the specified Page function example
PHP print output function summary sharing
# #
The above is the detailed content of PHP encapsulated MSSql operation class and complete example analysis. For more information, please follow other related articles on the PHP Chinese website!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php连接mssql数据库的方法有使用PHP的MSSQL扩展、使用PDO等。详细介绍:1、使用PHP的MSSQL扩展方法,确保PHP安装了MSSQL扩展。可以在PHP配置文件(php.ini)中检查是否启用了mssql扩展;2、使用PDO方法,确保PHP安装了PDO扩展。可以在PHP配置文件(php.ini)中检查是否启用了pdo_sqlsrv扩展。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

Ubuntu是一款流行的开源操作系统,常用于服务器运行。在Ubuntu上安装PHP并配置MSSQL连接是许多开发者和系统管理员经常需要做的操作之一。本文将为读者提供一份详细的指南,步骤包含安装PHP、设置Apache、安装MSSQLServer等内容,并附上具体的代码示例。第一步:安装PHP及相关扩展首先,我们需要安装PHP及其相关扩展,以便支持PHP连接

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
