Home>Article>Backend Development> What is the statement to delete database in php

What is the statement to delete database in php

藏色散人
藏色散人 Original
2021-11-03 11:22:32 2499browse

php statements to delete the database are such as "$sql="DELETE FROME guo WHERE iid=75839";". The delete statement can also delete all records in the table.

What is the statement to delete database in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

What is the statement to delete the database in php?

实例化数据表(如 $u=M()); $sql="DELETE FROME guo WHERE iid=75839"; $result=mysql_query($sql); if($result){ echo 删除成功 }else{echo 失败}

Related introduction:

MySQL provides us with delete and truncate statements to delete data.

Definition of delete statement:

The delete statement is mostly used when deleting data. Now let's look at the definition of delete statement.

DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name [WHERE where_definition] [ORDER BY ...] [LIMIT row_count] delete from friends where user_name = 'simaopig';

delete Note:

From the syntax structure, we can see that, like the update syntax, we can omit the where clause. But this is a very dangerous behavior. Because if you do not specify the where clause, delete will delete all the records in the table, and delete them immediately.

A brief description of the truncate statement:

I have never come into contact with this statement before, nor Not used. Because generally, everyone uses the delete statement to delete data. In fact, this truncate command is very simple. It means: delete all records in the table. It is equivalent to the delete statement without a where clause. The syntax structure is:

TRUNCATE [TABLE] tbl_name

Here is a simple example. I want to delete all the records in the friends table. I can use the following statement:

truncate table friends;

Efficiency issues of truncate and delete:

If you want to delete all data in the table, the truncate statement is faster than the delete statement. Because truncate deletes the table and then re-creates it according to the table structure, while delete deletes the records and does not try to modify the table. This is why when inserting data into a table that has been cleared using delete, MySQL will remember the previously generated AUTOINCREMENT sequence and continue to use it to number the AUTOINCREMENT fields. After truncate deletes the table, the table numbers the autoincrement fields starting from 1.

However, the truncate command is fast and fast, but it is not as safe for transaction processing as the delete command. Therefore, if the table we want to truncate is currently undergoing transaction processing, this command will exit with an error message.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the statement to delete database in php. For more information, please follow other related articles on the PHP Chinese website!

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