Home headlines PHP database operations--data preprocessing, update, delete

PHP database operations--data preprocessing, update, delete

Jun 27, 2018 pm 03:08 PM

Statement preprocessing: Generally speaking, it is a query and multiple executions. It will be often used in our later projects.

Creation:

//Creation preprocessing

$createinto=$connent->prepare("insert into zh(name,age,email) values (?,?,?)");
Copy after login

sql statement, the parameters use? instead of reserved

//绑定  
$createinto->bind_param("sis",$name,$age,$email);
Copy after login

The binding parameter s is String type i is int type

$name="zhanghao1";  
$age=1;  
$email="1234123123@qq.com";  
$createinto->execute();  
  
$name="zhanghao2";  
$age=2;  
$email="1234123123@qq.com";  
$createinto->execute();
Copy after login

Execute the statement; finally the data is inserted successfully. (The premise is to connect to the database and use)

Delete the specified entry:

mysqli_query($connent,"delete from zh where name='zhanghao1'");
Copy after login

Delete the entire table data without adding where conditions

Update the specified entry:

mysqli_query($connent,"update zh set age=3 where name='zhanghao2'");
Copy after login

Modify zhanghao2’s age to 3

Close the database after all database operations are completed.

----Complete code-------

connect_error){  
    die("连接失败: " . $connent->connect_error);  
}else{  
    echo "成功";  
  
}  
//创建预处理  
$createinto=$connent->prepare("insert into zh(name,age,email) values (?,?,?)");  
  
//绑定  
$createinto->bind_param("sis",$name,$age,$email);  
//多次执行  
$name="zhanghao1";  
$age=1;  
$email="1234123123@qq.com";  
$createinto->execute();  
  
$name="zhanghao2";  
$age=2;  
$email="1234123123@qq.com";  
$createinto->execute();  
echo "插入成功";  
  
//删除数据 删除表中 name为zhanghao1的数据  
mysqli_query($connent,"delete from zh where name='zhanghao1'");  
  
mysqli_query($connent,"update zh set age=3 where name='zhanghao2'");  
  
$connent->close();  
?>
Copy after login

We can find that where is the basis for judging conditions. According to it, we can conditionally query, Condition deletion and condition modification.

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
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)

Hot Topics

Java Tutorial
1671
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
How to implement real-time data updates in ECharts How to implement real-time data updates in ECharts Dec 17, 2023 pm 02:07 PM

ECharts is an open source visual chart library that supports various chart types and rich data visualization effects. In actual scenarios, we often need to display real-time data, that is, when the data source changes, the chart can be updated immediately and present the latest data. So, how to achieve real-time data update in ECharts? The following is a specific code demonstration example. First, we need to introduce ECharts’ js files and theme styles: <!DOCTYPEhtml>

Solve the problem of real-time update of Vue asynchronous request data Solve the problem of real-time update of Vue asynchronous request data Jun 30, 2023 pm 02:31 PM

How to solve the problem of real-time update of asynchronous request data in Vue development. With the development of front-end technology, more and more web applications use asynchronous request data to improve user experience and page performance. In Vue development, how to solve the problem of real-time update of asynchronous request data is a key challenge. Real-time update means that when the asynchronously requested data changes, the page can be automatically updated to display the latest data. In Vue, there are multiple solutions to achieve real-time updates of asynchronous data. 1. Responsive machine using Vue

How to dynamically bind and update form data in Vue How to dynamically bind and update form data in Vue Oct 15, 2023 pm 02:24 PM

How to dynamically bind and update form data in Vue With the continuous development of front-end development, forms are an interactive element that we often use. In Vue, dynamic binding and updating of forms is a common requirement. This article will introduce how to dynamically bind and update form data in Vue, and provide specific code examples. 1. Dynamic binding of form data Vue provides the v-model instruction to achieve two-way binding of form data. Through the v-model directive, we can compare the value of the form element with the Vue instance

Discuz online people counting function setting tips Discuz online people counting function setting tips Mar 10, 2024 am 09:33 AM

The setting skills of Discuz’s online people counting function require specific code examples. With the development of the Internet, the website’s online people counting function has gradually become one of the essential functions for website managers. Discuz is a very popular forum program. The setting of its online people statistics function is very important. It can provide website administrators with real-time access data, helping them better understand the access status of the website, so as to make corresponding adjustments and optimizations. . This article will introduce the setting skills of Discuz’s online people counting function and provide some suggestions.

How to use PHP functions for data preprocessing? How to use PHP functions for data preprocessing? May 02, 2024 pm 03:03 PM

PHP data preprocessing functions can be used for type conversion, data cleaning, date and time processing. Specifically, type conversion functions allow variable type conversion (such as int, float, string); data cleaning functions can delete or replace invalid data (such as is_null, trim); date and time processing functions can perform date conversion and formatting (such as date, strtotime, date_format).

How to use MySQL to implement data update operations in C# How to use MySQL to implement data update operations in C# Aug 01, 2023 pm 04:09 PM

How to use MySQL to implement data update operations in C# MySQL is a widely used relational database that provides powerful data management and query functions. In C# development, we often need to store data in MySQL and update the data when needed. This article will introduce how to use MySQL and C# to implement data update operations, and provide corresponding code examples. Step 1: Install MySQLConnector/NET Before starting, we need to install MySQLCo

Real-time data processing of MySql: how to achieve timely update of data Real-time data processing of MySql: how to achieve timely update of data Jun 16, 2023 am 08:27 AM

In database application development, the efficiency and accuracy of data processing are crucial. As data grows, real-time data processing becomes increasingly important to many businesses. In this case, MySQL has become one of the most popular relational databases, and vendors and developers need to focus on how to use MySQL to process real-time data. When working with real-time data, the main goal is to capture and process the data quickly and accurately. In order to achieve this, the following methods can be used: Indexing Indexing is the key to making the database quickly locate data.

How to realize real-time push and update of data in Vue technology development How to realize real-time push and update of data in Vue technology development Oct 08, 2023 pm 01:07 PM

How to realize real-time push and update of data in Vue technology development. With the continuous development of the Internet, real-time data push and update have become important needs in the development of modern Web applications. As a popular front-end development framework, Vue also provides some mechanisms and tools that can help us achieve real-time push and update of data. This article will introduce some commonly used methods and provide specific code examples to demonstrate their use. Using Vue's reactive mechanism Vue's reactive mechanism is one of the most important features of Vue. by in