Home php教程 php手册 四文章类封装对文章的各种操作插入数据库、从数据库取出等等

四文章类封装对文章的各种操作插入数据库、从数据库取出等等

Jun 13, 2016 am 10:24 AM
write right encapsulation insert operate database article of kind

WHXBB(); } /** * 文章写入数据库 * @param $title 文章标题 * @param $author 文章作者 * @param $content 文章内容 * @return 操作出错:一个WHXBB_Error对象 成功:true * @access public */ function Insert($title, $author, $content) { new WHXBB_Debug("Insert() Start"); // 处理传入的参数 WHXBB::OperateString(&$title, in); WHXBB::OperateString(&$author, in); WHXBB::OperateString(&$content, in); $sql = "insert into article(title,author,content) values($title,$author,$content)"; if( !@mysql_query($sql, $this->_conn) ) { return new WHXBB_Error("Insert() Failed.($sql)", 1021); } new WHXBB_Debug("Insert() Completed"); return true; } /** * 删除指定的记录 * @param $id 要删除记录的id * @return 操作出错:一个WHXBB_Error对象 成功:true * @access public */ function Del($id) { new WHXBB_Debug("Del($id) Start"); $sql = "delete from article where id=$id)"; if( !@mysql_query($sql, $this->_conn) ) { return new WHXBB_Error("Del() Failed.($sql)", 1024); } new WHXBB_Debug("Dle($id) Completed"); return true; } /** * 得到文章的总数 * @param $condition 查询条件 * @return 操作出错:一个WHXBB_Error对象 成功:true * @access public */ function GetCount($condition = ) { new WHXBB_Debug("GetCount() Start"); $sql = "select count(id) from article where 1=1 $condition"; if( !$result = @mysql_query($sql, $this->_conn)) { return new WHXBB_Error("GetCount() Failed.($sql)", 1000); } list($count) = @mysql_fetch_array($result); @mysql_free_result($result); new WHXBB_Debug("GetCount() Completed"); return $count; } /** * 得到某一篇文章的所有字段信息 * @param $id 文章id号 * @return 操作出错:一个WHXBB_Error对象 成功:返回一个关联数组 找不到信息:返回0 * @access public */ function GetInfo($id ) { new WHXBB_Debug("GetInfo($id) Start"); $sql = "select id, title, content, author from article where id=$id"; $result = @mysql_query($sql, $this->_conn); if( !$result) return new WHXBB_Error("GetInfo($id) Failed.($sql)", 1002); if(@mysql_num_rows($result) == 0) return 0; $info = @mysql_fetch_array($result); while (list($var, $key) = each($info)) { WHXBB::OperateString(&$info[$var], out); } reset($info); @mysql_free_result($result); new WHXBB_Debug("GetInfo($id) Completed"); return $info; } /** * 得到所有author为指定作者名的所有记录 * @param $items 每页显示条数,如果为0则表示取出所有记录 * @param page 当前页码 * @param author 作者名 * @param $orderBy 排序方式 * @return 操作出错:一个WHXBB_Error对象 成功:返回一个数组 找不到信息:返回0 * @access public */ function GetNInfoByAuthor($items, $page, $author, $orderBy = order by id desc) { WHXBB::OperateString(&$author, in); $condition = " and author=$author "; $result = $this->GetNInfo($items, $page, $condition, $orderBy); return $result; } } /** * 列出所有记录 * @param $items 每页显示条数,如果为0则表示取出所有记录 * @param $page 当前页码 * @param $condition 查询条件 * @param $orderBy 排序方式 * @return 操作出错:一个WHXBB_Error对象 成功:返回一个二维数组 找不到信息:返回0 * @access public */ function GetNInfo($items, $page, $condition = , $orderBy = order by id desc) { new WHXBB_Debug("GetNInfo() Start"); $limit = ; //取记录总数 $infoCount = $this->GetCount($condition); if ($infoCount == 0) return 0; if ($items != 0) { // 新建一个分页器 $this->pager = new Pager($infoCount, $items, $page); $startPos = $this->pager->startPos; $limit = " limit ".$startPos.", ".$items; } $sql = "select id, title, author from article where 1=1 $condition $orderBy $limit"; $result = @mysql_query($sql, $this->_conn); if( !$result ) return new WHXBB_Error("GetNInfo() Failed.($sql)", 1001); if(@mysql_num_rows($result) == 0) return 0; $i = 0; while ($arr = @mysql_fetch_array($result)) { while(list($var, $key) = each($arr)) { WHXBB::OperateString(&$arr[$var], out); } reset($arr); $info[$i] = $arr; $i++; } @mysql_free_result($result); new WHXBB_Debug("GetNInfo() Completed"); return $info; } } ?>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

TrendForce: Nvidia's Blackwell platform products drive TSMC's CoWoS production capacity to increase by 150% this year TrendForce: Nvidia's Blackwell platform products drive TSMC's CoWoS production capacity to increase by 150% this year Apr 17, 2024 pm 08:00 PM

According to news from this site on April 17, TrendForce recently released a report, believing that demand for Nvidia's new Blackwell platform products is bullish, and is expected to drive TSMC's total CoWoS packaging production capacity to increase by more than 150% in 2024. NVIDIA Blackwell's new platform products include B-series GPUs and GB200 accelerator cards integrating NVIDIA's own GraceArm CPU. TrendForce confirms that the supply chain is currently very optimistic about GB200. It is estimated that shipments in 2025 are expected to exceed one million units, accounting for 40-50% of Nvidia's high-end GPUs. Nvidia plans to deliver products such as GB200 and B100 in the second half of the year, but upstream wafer packaging must further adopt more complex products.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

AMD 'Strix Halo” FP11 package size exposed: equivalent to Intel LGA1700, 60% larger than Phoenix AMD 'Strix Halo” FP11 package size exposed: equivalent to Intel LGA1700, 60% larger than Phoenix Jul 18, 2024 am 02:04 AM

This website reported on July 9 that the AMD Zen5 architecture "Strix" series processors will have two packaging solutions. The smaller StrixPoint will use the FP8 package, while the StrixHalo will use the FP11 package. Source: videocardz source @Olrak29_ The latest revelation is that StrixHalo’s FP11 package size is 37.5mm*45mm (1687 square millimeters), which is the same as the LGA-1700 package size of Intel’s AlderLake and RaptorLake CPUs. AMD’s latest Phoenix APU uses an FP8 packaging solution with a size of 25*40mm, which means that StrixHalo’s F

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How do C++ functions improve the efficiency of GUI development by encapsulating code? How do C++ functions improve the efficiency of GUI development by encapsulating code? Apr 25, 2024 pm 12:27 PM

By encapsulating code, C++ functions can improve GUI development efficiency: Code encapsulation: Functions group code into independent units, making the code easier to understand and maintain. Reusability: Functions create common functionality that can be reused across applications, reducing duplication and errors. Concise code: Encapsulated code makes the main logic concise and easy to read and debug.

See all articles