mysql class comments throughout
Profile Section
<?php /** * Created by wangsir * User: Administrator * Date: 14-12-22 * Time: 上午9:29 */ define('DB_MS','mysql'); //服务器 define('DB_USER','root'); //数据库用户名 define('DB_PASSWD','111'); //数据库密码 define('DB_NAME','bbs'); //使用数据库 define('DB_HOST','localhost'); //数据库服务器 define('DB_COD','utf8'); //数据库编码 define('DB_DSN',DB_MS.':host='.DB_HOST.';dbname='.DB_NAME);
Class
<?php /** * Created by wangsir. * Date: 14-12-22 * Time: 上午9:22 * 本扩展自 PHP 5.5.0 起已废弃,并在将来会被移除。 */ header("Content-Type:text/html;charset=utf-8"); //包含配置文件 require_once("config.ini.php"); class MySqli { public $conn; //保存数据库连接资源 public $host; //服务器 public $username; //数据库用户名 public $password; //数据密码 public $dbname; //数据库名 public $cod; //数据库编码 public $dataTable; //数据库表 public $sql; //sql语句 public $where; //条件 public $limit; //几条数据 public $select; //查询 //数据库连接 //这里采用读取配置文件的方式获取基本信息 也可以在构造函数传数组来解决同样的问题 public function __construct($host=DB_HOST ,$username=DB_USER,$passwd=DB_PASSWD,$dbname=DB_NAME,$cod=DB_COD) { //获取数据库长连接,因为有长连接了所以就不在做单例模式 $this->conn = new mysqli($host,$username,$passwd); $this->selectDb($dbname); $this->coding($cod); } //设置编码格式 public function coding($cod) { mysql_query("SET CHARACTER SET ".$cod); } //读取某个库 public function selectDb($dbname) { mysql_select_db($dbname,$this->conn); } //要查询什么字段 这个事查询的最后一步 public function select($field="*") { $this->sql = "select ".$field." from ".$this->dataTable.$this->where.$this->limit; } //要使用哪个表 public function table($tableName) { $this->dataTable = $tableName; return $this; } //执行操作 public function query() { $res = mysql_query($this->sql); //是资源类型代表查询 返回结果数组 if(is_resource($res)) { //将返回二维数组 while($row = mysql_fetch_assoc($res)) { $arr[] = $row; } //返回一维数组 foreach($arr as $key=>$value) { $ke = $value; } return $ke; } } //取得几个值 limit public function limit($limit) { $this->limit = ' limit '.$limit; return $this; } //where条件 public function where($where) { $this->where = ' where '.$where; return $this; } //insert public function insert($insert) { //如果是索引数组 if($this->is_assoc($insert)) { //获取数组的key 也就是字段值 $key = array_keys($insert); $value = array_values($insert); for($i=0,$j=0;$i<count($key),$j<count($value);$i++,$j++) { $column.=$key[$i].','; $val.=$value[$j].','; } $col = rtrim($column,','); $value = rtrim($val,','); $this->sql = "insert into ".$this->dataTable."($col) values($value)"; }else{ //如果不是索引数组 那么直接将数组转化为字符串 $value = implode(',',$insert); $this->sql = "insert into ".$this->dataTable." values($value)"; } } //修改 public function update($update) { foreach($update as $key=>$value) { $data.=$key."=".$value.','; } $values = rtrim($data,','); $this->sql = "UPDATE ".$this->dataTable." SET $values ".$this->where; } //删除 public function delete() { $this->sql = "DELETE FROM ".$this->dataTable.$this->where; } //判断是否为索引数组 public function is_assoc($array) { if(is_array($array)) { $keys = array_keys($array); return $keys != array_keys($keys); } return false; } } //$b = array('CategoryID'=>9,'Name'=>11,'Description'=>22,'Priority'=>35); //$b = array(4,5,6,7); //$a = new MySqli(); //查询 //$sql = $a->table("guagua_category")->where('CategoryID=1')->limit(3)->select(); //$arr = $a->query(); //插入 //$sql = $a->table("guagua_category")->insert($b); //$a->query(); //修改 //$sql = $a->table("guagua_category")->where("CategoryID=1")->update($b); //$a->query(); //删除 //$sql = $a->table("guagua_category")->where("CategoryID=9")->delete(); //$a->query();
The above introduces the mysql class and comments throughout the article, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Every year before Apple releases a new major version of iOS and macOS, users can download the beta version several months in advance and experience it first. Since the software is used by both the public and developers, Apple has launched developer and public versions, which are public beta versions of the developer beta version, for both. What is the difference between the developer version and the public version of iOS? Literally speaking, the developer version is a developer test version, and the public version is a public test version. The developer version and the public version target different audiences. The developer version is used by Apple for testing by developers. You need an Apple developer account to download and upgrade it.

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

A colleague got stuck due to a bug pointed by this. Vue2’s this pointing problem caused an arrow function to be used, resulting in the inability to get the corresponding props. He didn't know it when I introduced it to him, and then I deliberately looked at the front-end communication group. So far, at least 70% of front-end programmers still don't understand it. Today I will share with you this link. If everything is wrong If you haven’t learned it yet, please give me a big mouth.

Watch4pro and gt each have different features and applicable scenarios. If you focus on comprehensive functions, high performance and stylish appearance, and are willing to bear a higher price, then Watch 4 Pro may be more suitable. If you don’t have high functional requirements and pay more attention to battery life and reasonable price, then the GT series may be more suitable. The final choice should be decided based on personal needs, budget and preferences. It is recommended to carefully consider your own needs before purchasing and refer to the reviews and comparisons of various products to make a more informed choice.

The Java public access modifier allows functions to be accessed from anywhere and is used to declare public APIs and define tools and utilities that are shared across packages or classes. The specific usage is as follows: Syntax: public return value type function name (parameter list) {...} Scenario: functions that need to be accessed from anywhere, methods in public APIs, shared tools or utilities
