Home Backend Development PHP Tutorial mysql.class.php link database class_PHP tutorial

mysql.class.php link database class_PHP tutorial

Jul 13, 2016 pm 05:45 PM
database file name kind Link

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;$i<$this->num_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 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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to get the WeChat video account link? How to add product links to WeChat video account? How to get the WeChat video account link? How to add product links to WeChat video account? Mar 22, 2024 pm 09:36 PM

As part of the WeChat ecosystem, WeChat video accounts have gradually become an important promotion tool for content creators and merchants. Getting links to video accounts on this platform is crucial for sharing and disseminating content. The following will introduce in detail how to obtain the WeChat video account link and how to add product links to the video account to improve the dissemination effect of the content. 1. How to get the WeChat video account link? After posting a video on your WeChat video account, the system will automatically create a video link. Authors can copy the link after publishing to facilitate sharing and dissemination. After logging in to your WeChat video account, you can browse the homepage of your video account. On the home page, each video is accompanied by a corresponding link so you can copy or share it directly. 3. Search video account: Enter the video account name in the WeChat search box

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Steps to solve the problem that the file name is too long and cannot be deleted in Windows 10 Steps to solve the problem that the file name is too long and cannot be deleted in Windows 10 Mar 27, 2024 pm 04:41 PM

1. First find the file or folder that you need to delete. Because the file name is too long, the system will prompt when performing the deletion operation, [The file or directory cannot be deleted because the file name is too long]; as shown in the figure: 2 . At this time, use the shortcut key [Win+R] to open Run, enter [cmd], and open the command prompt after confirmation; as shown in the figure: 3. First switch to the disk where the file is located, mine is in D, enter [D:] , and then switch to the folder where the file is located. Mine is in [1], enter [cd1], and then enter [dir] to see all the files in the directory. In my directory, there is only one file that needs to be deleted. ;As shown in the figure: 4. Enter [del*.png] at this time, that is, all files with the suffix png in the directory will be

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 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.

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

Java how to loop through a folder and get all file names Java how to loop through a folder and get all file names Mar 29, 2024 pm 01:24 PM

Java is a popular programming language with powerful file handling capabilities. In Java, traversing a folder and getting all file names is a common operation, which can help us quickly locate and process files in a specific directory. This article will introduce how to implement a method of traversing a folder and getting all file names in Java, and provide specific code examples. 1. Use the recursive method to traverse the folder. We can use the recursive method to traverse the folder. The recursive method is a way of calling itself, which can effectively traverse the folder.

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.

See all articles