search
HomeBackend DevelopmentPHP Tutorialmysql.class.php link database class_PHP tutorial

File name mysql.class.php

//###################### Start Introduce ####################### ###############
// mysql connection class
// author: bluemaple , emaile: bluemaple@x263.net
// You can execute general mysql commands, such as insert, delete, select, update
// How to use: Add
in front of the required files // require("./mysql.class.php");
// $DB=new DB_MYSQL; // Loading class
// $DB->dbServer="localhost"; // Connection database address
// $DB->dbUser="root"; // Username
// $DB->dbPwd=""; // Password
// $DB->dbDatabase="we"; // Database name
// $DB->connect(); // Connect to database
//You can change the database during use
// Description of functions that can be used
// query($sql,$dbbase);                                                                                                // can be executed directly
// query_first($sql,$dbbase); // The query returns only one record, $sql is the sql statement, and $dbbase selects the database for you (optional)
// fetch_array($sql,$dbbase); // The query returns a set of records, and you can use num_rows to get the returned number
// insert, update, delete are all execution commands, in which $affected_rows; can be used to get the returned number
// When inserting, you can use insert_id to get the returned id number of the insertion result
// count_records($table,$index,$where,$dbbase)//To get the number of records in a table, $table is the table name, $index is the key, $where is the condition, $dbbase is the database, the last two You don’t need to select
//###################### End Introduce ####################### #################

class DB_MYSQL // Database mysql query class
{
var $dbServer; // Database connection service address
var $dbDatabase; //Selected database, initial state
var $dbbase=""; // This can be changed later
var $dbUser; // Login username
var $dbPwd; // Login user password
var $dbLink; // Database connection pointer
var $query_id; // Pointer to execute query command
var $num_rows; // Number of entries returned
var $insert_id; // Return the ID of the last INSERT command used
var $affected_rows; // Return the number of columns affected by the query command
// The number of columns (ROW) affected by Insert, Update or Delete.
// delete without where, then returns 0
       
function connect($dbbase="") // Database connection function, including database connection
           {
​​​​​ global $usepconnect; // Whether to use a permanent connection, $userpconnect is set externally.
             if ($usepconnect==1){
                     $this->dbLink=@mysql_pconnect($this->dbServer,$this->dbUser,$this->dbPwd);
                                                                                                                                                                                                                                      $this->dbLink=@mysql_connect($this->dbServer,$this->dbUser,$this->dbPwd);
                }
If(!$this->dbLink) $this->halt("Connection error, unable to connect!!!");
               if ($dbbase=="") {
                 $dbbase=$this->dbDatabase;
                                                                                                        If(!mysql_select_db($dbbase, $this->dbLink)) // Connect to database
{ $this->halt("This database cannot be used, please check whether the database is correct!!!");}
          }

function change_db($dbbase=""){ // Change database
$this->connect($dbbase);
}

  function query_first($sql,$dbbase=""){ // 返回一个值的sql命令
      $query_id=$this->query($sql,$dbbase);
        $returnarray=mysql_fetch_array($query_id);
        $this->num_rows=mysql_num_rows($query_id);
      $this->free_result($query_id);      
      return $returnarray;
      }
 
  function fetch_array($sql,$dbbase="",$type=0){ // 返回一个值的sql命令
                           // type为传递值是name=>value,还是4=>value
      $query_id=$this->query($sql,$dbbase);
      $this->num_rows=mysql_num_rows($query_id);
      for($i=0;$inum_rows;$i++){
          if($type==0)
              $array[$i]=mysql_fetch_array($query_id);
          else
              $array[$i]=mysql_fetch_row($query_id);
          }
      $this->free_result($query_id);
      return $array;
      }
 
  function delete($sql,$dbbase=""){ // 删除命令
      $query_id=$this->query($sql,$dbbase);
      $this->affected_rows=mysql_affected_rows($this->dbLink);
      $this->free_result($query_id);
        }
 
  function insert($sql,$dbbase=""){ // 插入命令
      $query_id=$this->query($sql,$dbbase);
      $this->insert_id=mysql_insert_id($this->dbLink);
      $this->affected_rows=mysql_affected_rows($this->dbLink);
      $this->free_result($query_id);
        }
 
  function update($sql,$dbbase=""){  //  更新命令
      $query_id=$this->query($sql,$dbbase);
      $this->affected_rows=mysql_affected_rows($this->dbLink);      
      $this->free_result($query_id);
      }
 
  function count_records($table,$index="id",$where="",$dbbase=""){ // 记录总共表的数目
                                                   // where为条件
                                                   // dbbase为数据库
                                                   // index为所选key,默认为id
        if($dbbase!="") $this->change_db($dbbase);
        $result=@mysql_query("select count(".$index.") as 'num' from $table ".$where,$this->dbLink);
        if(!$result) $this->halt("错误的SQL语句: ".$sql);
        @$num = mysql_result($result,0,"num");    
        return $num;
      }
 
function query($sql,$dbbase=""){ // Execute queyr command
If($dbbase!="") $this->change_db($dbbase);
$this->query_id=@mysql_query($sql,$this->dbLink);
echo "d";
If(!$this->query_id) $this->halt("Wrong SQL statement: ".$sql);
Return $this->query_id;
}
 
function halt($errmsg) // Database error, unable to connect successfully
           {
                  $msg="

Database error!


";
                $msg.=$errmsg;
                  echo $msg;
             die();
}

function free_result($query_id) // Release query selector
           {
           @mysql_free_result($query_id);
}

function close() //Close the database connection
           {
mysql_close($this->dbLink);
}
}
?>

Here’s how to use it

text.php

require("./mysql.class.php");
$DB=new DB_MYSQL;
$DB->dbServer="localhost";
$DB->dbUser="root";
$DB->dbPwd="";
$DB->dbDatabase="we";
$DB->connect(); // Connect to database
?>

from Fantasy Spring Continent

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478652.htmlTechArticleFile name mysql.class.php ? //############## ######## Start Introduce ###################################### / / mysql connection class // author: bluemaple , emaile: bluemaple@x263.net // Can...
Statement
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
如何使用磁力链接如何使用磁力链接Feb 18, 2024 am 10:02 AM

磁力链接是一种用于下载资源的链接方式,相比传统的下载方式更为便捷和高效。使用磁力链接可以通过点对点的方式下载资源,而不需要依赖中介服务器。本文将介绍磁力链接的使用方法及注意事项。一、什么是磁力链接磁力链接是一种基于P2P(Peer-to-Peer)协议的下载方式。通过磁力链接,用户可以直接连接到资源的发布者,从而完成资源的共享和下载。与传统的下载方式相比,磁

115://开头的链接怎么下载?下载方法介绍115://开头的链接怎么下载?下载方法介绍Mar 14, 2024 am 11:58 AM

  最近有很多用户都在问小编,115://开头的链接怎么下载?想要下载115://开头的链接需要借助115浏览器,大家下载好115浏览器后,再来看看下面小编整理好的下载教程吧。  115://开头的链接下载方法介绍  1、登录115.com,下载115浏览器并安装。  2、在115浏览器地址栏输入:chrome://extensions/,进入扩展中心,搜索Tampermonkey,安装对应插件。  3、在115浏览器地址栏输入:  油猴脚本:https://greasyfork.org/en/

如何获取微信视频号链接?微信视频号怎么添加商品链接?如何获取微信视频号链接?微信视频号怎么添加商品链接?Mar 22, 2024 pm 09:36 PM

微信视频号作为微信生态系统的一部分,已经逐渐成为内容创作者和商家的重要推广工具。在这个平台上获取视频号链接对于分享和传播内容至关重要。下文将详细介绍如何获取微信视频号链接,以及如何在视频号中添加商品链接,提升内容的传播效果。一、如何获取微信视频号链接?在微信视频号中发布视频后,系统会自动创建一个视频链接。作者可以在发布后复制该链接,方便进行分享和传播。登录微信视频号后,您可以浏览自己的视频号主页。在主页上,每个视频都附有相应的链接,方便您直接复制或分享。3.搜索视频号:在微信搜索框中输入视频号名

如何在最新的iOS 17系统中连接iPhone上的Apple Notes如何在最新的iOS 17系统中连接iPhone上的Apple NotesSep 22, 2023 pm 05:01 PM

使用添加链接功能在iPhone上链接AppleNotes。笔记:如果您已安装iOS17,则只能在iPhone上的AppleNotes之间创建链接。在iPhone上打开“备忘录”应用。现在,打开要在其中添加链接的注释。您还可以选择创建新备忘录。点击屏幕上的任意位置。这将向您显示一个菜单。点击右侧的箭头以查看“添加链接”选项。点击它。现在,您可以键入注释的名称或网页URL。然后,点击右上角的完成,添加的链接将出现在笔记中。如果要添加指向某个单词的链接,只需双击该单词即可将其选中,选择“添加链接”并按

视频号挂链接需要什么条件?视频号带货怎么挂链接?视频号挂链接需要什么条件?视频号带货怎么挂链接?Mar 07, 2024 pm 01:13 PM

随着短视频平台的盛行,越来越多的创作者开始利用视频号来创作和推广内容。视频号不仅可以展示个人才能,还可以通过带货链接来实现商业变现。但是,要在视频号中添加链接,必须符合一定的条件。一、视频号挂链接需要什么条件?视频号认证是在视频号中添加链接的前提条件。目前,主要的短视频平台如抖音、快手等都提供认证服务,主要包括个人认证和机构认证两种类型。个人认证需要提交真实身份信息,而机构认证则需要提供相关企业或组织的认证材料。完成认证后,用户可以在视频号中添加链接,提升账号的可信度和权威性。视频号挂链接的一个

如何禁止 Outlook 在 Edge 浏览器中打开链接如何禁止 Outlook 在 Edge 浏览器中打开链接Aug 03, 2023 am 11:49 AM

如何阻止Outlook在Edge中打开链接在继续之前,请确保您的首选浏览器在Windows中设置为默认浏览器。这可确保在所需的浏览器中打开Outlook链接。要检查并设置默认浏览器:对于Windows10:单击“开始”菜单,然后选择“设置”转到“应用程序”,然后转到“默认应用程序”在默认应用程序列表的底部查找“Web浏览器”如果列出了您的首选浏览器,则一切就绪。如果列出了MicrosoftEdge,请单击它,然后从列表中选择您喜欢的浏览器。如果出现提示,请单击“仍然切换”。修复Edge问题中Ou

深入理解MySQL索引优化器工作原理深入理解MySQL索引优化器工作原理Nov 09, 2022 pm 02:05 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于索引优化器工作原理的相关内容,其中包括了MySQL Server的组成,MySQL优化器选择索引额原理以及SQL成本分析,最后通过 select 查询总结整个查询过程,下面一起来看一下,希望对大家有帮助。

抖店怎么上链接-抖店上链接教程抖店怎么上链接-抖店上链接教程Mar 06, 2024 am 08:40 AM

有很多朋友还不知道抖店怎么上链接,所以下面小编就讲解了抖店上链接的方法教程,有需要的小伙伴赶紧来看一下吧,相信对大家一定会有所帮助哦。第一步:首先打开抖店电脑端,进入左边栏“橱窗商品管理”,如图所示。第二步:接着点击右上角的“添加商品”,如图所示。第三步:然后将我们的商品链接复制粘贴进去,如图所示。第四步:随后点击“确认添加”,如图所示。第五步:最后输入介绍、图片等信息,再点击“确认”就能在抖音上链接了,如图所示。上面就是小编为大家带来的抖店怎么上链接的全部内容,希望对大家能够有所帮助哦。

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools