Home Backend Development PHP Problem How to add, delete, modify and check mysql in php

How to add, delete, modify and check mysql in php

Sep 25, 2019 am 10:06 AM
Add, delete, modify and check

How to add, delete, modify and check mysql in php

When PHP is connecting to the database in the following code, it uses the four major functions of mysql operations: add, delete, modify, and check. The source code is as follows:

Connect to the database

<?php
$conn=mysql_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;&#39;);
if(!$conn){
echo "connect failed";
exit;
}
$sql=&#39;use student&#39;;
mysql_query($sql,$conn);
Copy after login

Add

$sql="insert into student(sname,sage) values(&#39;wx&#39;,&#39;18&#39;)";
$rs=mysql_query($sql,$conn);
if($rs){
    echo &#39;insert data success&#39;."<br />";
}else{
    echo &#39;insert data failed&#39;."<br />";
}
Copy after login

Delete

$sql="delete from student where sname=&#39;li&#39;";
$rs=mysql_query($sql,$conn);
if($rs){
    echo &#39;del data success&#39;."<br />";
}else {
    echo &#39;del data failed&#39;."<br />";    
}
Copy after login

Modify

$sql="update student set sname=&#39;fu&#39; where sname=&#39;pu&#39;";
$rs=mysql_query($sql,$conn);
if($rs){
    echo &#39;update data success&#39;."<br />";
}else{
    echo &#39;update data failed&#39;."<br />";
}
Copy after login

Query

$sql="select * from student";
$rs=mysql_query($sql,$conn);
var_dump($rs);
while($row=mysql_fetch_object($rs)){
print_r($row);
echo &#39;   &#39;;
echo $row->sname ."<br>">;
}
?>
Copy after login

The above is the detailed content of How to add, delete, modify and check mysql in php. For more information, please follow other related articles on the PHP Chinese website!

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)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1264
29
C# Tutorial
1237
24
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.

Java List Interface Example Demonstration: Data Operation to Implement Add, Delete, Modify and Check Operations Java List Interface Example Demonstration: Data Operation to Implement Add, Delete, Modify and Check Operations Dec 20, 2023 am 08:10 AM

The JavaList interface is one of the commonly used data structures in Java, which can easily implement data addition, deletion, modification and query operations. This article will use an example to demonstrate how to use the JavaList interface to implement data addition, deletion, modification and query operations. First, we need to introduce the implementation class of the List interface in the code, the common ones are ArrayList and LinkedList. Both classes implement the List interface and have similar functions but different underlying implementations. ArrayList is based on array real

CRUD operation of MySql: how to quickly complete addition, deletion, modification and query CRUD operation of MySql: how to quickly complete addition, deletion, modification and query Jun 15, 2023 pm 11:30 PM

MySql is a relational database management system that is very commonly used in web applications. In the entire web application development process, CRUD (Create, Delete, Modify and Check) operations are essential. This article will introduce how to quickly complete these operations in MySql. Add (Create) In MySql, we use the INSERTINTO statement to insert new rows. For example, we have a table called "users" with three columns: "id", "name" and "email". Now

How to use collection framework functions to add, delete, modify and query collections in Java How to use collection framework functions to add, delete, modify and query collections in Java Oct 25, 2023 am 08:45 AM

How to use collection framework functions in Java to perform addition, deletion, modification, and query operations on collections. In Java, the collection framework (CollectionFramework) provides a series of classes and interfaces to facilitate our collection operations. These classes and interfaces contain a wealth of functions that allow us to add, delete, modify, and search collections more conveniently. Below we'll detail how to use collections framework functions to perform these operations, and provide specific code examples. The addition operation of a collection can be done in Java

How to handle the addition, deletion, modification and query operations of form data in Vue technology development How to handle the addition, deletion, modification and query operations of form data in Vue technology development Oct 10, 2023 pm 02:49 PM

How to handle the addition, deletion, modification and query operations of form data in Vue technology development. In the development of Vue technology, the addition, deletion, modification and query operations of form data are very common requirements. This article will introduce how to use Vue technology to handle these operations and provide specific code examples. First, we need to create a Vue instance and define an empty array in the data attribute to store the form data. For example: newVue({data(){return{formData:[

Sharing of techniques for adding, deleting, modifying and checking JSON arrays in Java. Sharing of techniques for adding, deleting, modifying and checking JSON arrays in Java. Sep 06, 2023 am 11:28 AM

Sharing skills for adding, deleting, modifying and querying JSON arrays in Java Introduction: JSON (JavaScriptObjectNotation) is a lightweight data exchange format that is widely used in various Internet applications. In Java, we can operate on JSON by using some third-party libraries, such as GSON, Jackson, etc. This article will share some techniques for adding, deleting, modifying and checking JSON arrays in Java, and provide corresponding code examples. one,

Add, delete, modify and query operations of XML data in Python Add, delete, modify and query operations of XML data in Python Aug 08, 2023 pm 09:17 PM

Add, delete, modify, and query operations on XML data in Python XML (Extensible Markup Language) is a text format used to store and transmit data. In Python, we can use a variety of libraries to process XML data, the most commonly used of which is the xml.etree.ElementTree library. This article will introduce how to use Python to add, delete, modify and query XML data, and illustrate it through code examples. 1. Introduction of modules First, we need to introduce xml.etree.Eleme

How to use PHP to implement data addition, deletion, modification and query operations How to use PHP to implement data addition, deletion, modification and query operations Sep 25, 2023 am 10:43 AM

How to use PHP to implement data addition, deletion, modification and query operations. In web development, it is often necessary to perform addition, deletion, modification and query operations on the database. As a popular server-side programming language, PHP provides a wealth of functions and classes to conveniently operate databases. This article will introduce how to use PHP to implement data addition, deletion, modification and query operations, and provide specific code examples. Connecting to the database In PHP, you can use mysqli or PDO to connect to the database. The following is a sample code for using mysqli to connect to the database: $serverna

See all articles